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 2017/09/09 14:18:58 UTC
[05/14] camel git commit: CAMEL-11756: camel-spring-boot2 - Work in
progress
http://git-wip-us.apache.org/repos/asf/camel/blob/cb70f538/components/camel-spring-boot2/src/main/java/org/apache/camel/spring/boot/SpringTypeConverter.java
----------------------------------------------------------------------
diff --git a/components/camel-spring-boot2/src/main/java/org/apache/camel/spring/boot/SpringTypeConverter.java b/components/camel-spring-boot2/src/main/java/org/apache/camel/spring/boot/SpringTypeConverter.java
new file mode 100644
index 0000000..af062b4
--- /dev/null
+++ b/components/camel-spring-boot2/src/main/java/org/apache/camel/spring/boot/SpringTypeConverter.java
@@ -0,0 +1,85 @@
+/**
+ * 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.Collection;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.TypeConversionException;
+import org.apache.camel.support.TypeConverterSupport;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.core.convert.ConversionFailedException;
+import org.springframework.core.convert.ConversionService;
+import org.springframework.core.convert.ConverterNotFoundException;
+import org.springframework.core.convert.TypeDescriptor;
+
+public class SpringTypeConverter extends TypeConverterSupport {
+
+ private final List<ConversionService> conversionServices;
+ private final ConcurrentHashMap<Class<?>, TypeDescriptor> types;
+
+ @Autowired
+ public SpringTypeConverter(List<ConversionService> conversionServices) {
+ this.conversionServices = conversionServices;
+ this.types = new ConcurrentHashMap<>();
+ }
+
+ @Override
+ public <T> T convertTo(Class<T> type, Exchange exchange, Object value) throws TypeConversionException {
+ // do not attempt to convert Camel types
+ if (type.getCanonicalName().startsWith("org.apache")) {
+ return null;
+ }
+
+ // do not attempt to convert List -> Map. Ognl expression may use this converter as a fallback expecting null
+ if (type.isAssignableFrom(Map.class) && (value.getClass().isArray() || value instanceof Collection)) {
+ return null;
+ }
+
+ TypeDescriptor sourceType = types.computeIfAbsent(value.getClass(), TypeDescriptor::valueOf);
+ TypeDescriptor targetType = types.computeIfAbsent(type, TypeDescriptor::valueOf);
+
+ for (ConversionService conversionService : conversionServices) {
+ if (conversionService.canConvert(sourceType, targetType)) {
+ try {
+ return (T)conversionService.convert(value, sourceType, targetType);
+ } catch (ConversionFailedException e) {
+ // if value is a collection or an array the check ConversionService::canConvert
+ // may return true but then the conversion of specific objects may fail
+ //
+ // https://issues.apache.org/jira/browse/CAMEL-10548
+ // https://jira.spring.io/browse/SPR-14971
+ //
+ if (e.getCause() instanceof ConverterNotFoundException && isArrayOrCollection(value)) {
+ return null;
+ } else {
+ throw new TypeConversionException(value, type, e);
+ }
+ }
+ }
+ }
+
+ return null;
+ }
+
+ private boolean isArrayOrCollection(Object value) {
+ return value instanceof Collection || value.getClass().isArray();
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/cb70f538/components/camel-spring-boot2/src/main/java/org/apache/camel/spring/boot/SupervisingRouteControllerAutoConfiguration.java
----------------------------------------------------------------------
diff --git a/components/camel-spring-boot2/src/main/java/org/apache/camel/spring/boot/SupervisingRouteControllerAutoConfiguration.java b/components/camel-spring-boot2/src/main/java/org/apache/camel/spring/boot/SupervisingRouteControllerAutoConfiguration.java
new file mode 100644
index 0000000..0ac9994
--- /dev/null
+++ b/components/camel-spring-boot2/src/main/java/org/apache/camel/spring/boot/SupervisingRouteControllerAutoConfiguration.java
@@ -0,0 +1,93 @@
+/**
+ * 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.Collections;
+import java.util.List;
+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.SupervisingRouteControllerFilters;
+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;
+ @Autowired(required = false)
+ private List<SupervisingRouteController.Filter> filters = Collections.emptyList();
+
+ @Bean
+ @Scope(ConfigurableBeanFactory.SCOPE_SINGLETON)
+ @ConditionalOnMissingBean
+ public RouteController routeController() {
+ SupervisingRouteController controller = new SupervisingRouteController();
+
+ // Initial delay
+ Optional.ofNullable(configuration.getInitialDelay()).map(TimePatternConverter::toMilliSeconds).ifPresent(controller::setInitialDelay);
+
+ // Filter list
+ controller.setFilters(filters);
+
+ // Back off
+ controller.setDefaultBackOff(configureBackOff(Optional.empty(), configuration.getDefaultBackOff()));
+
+ for (Map.Entry<String, RouteConfiguration> entry: configuration.getRoutes().entrySet()) {
+ final RouteConfiguration cfg = entry.getValue();
+ final Optional<BackOff> defaultBackOff = Optional.ofNullable(controller.getDefaultBackOff());
+
+ if (!cfg.isSupervised()) {
+ // Mark this route as excluded from supervisor
+ controller.addFilter(new SupervisingRouteControllerFilters.BlackList(entry.getKey()));
+ } else {
+ // configure teh route
+ controller.setBackOff(entry.getKey(), configureBackOff(defaultBackOff, cfg.getBackOff()));
+ }
+ }
+
+ return controller;
+ }
+
+ private BackOff configureBackOff(Optional<BackOff> template, BackOffConfiguration conf) {
+ final BackOff.Builder builder = template.map(BackOff::builder).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/cb70f538/components/camel-spring-boot2/src/main/java/org/apache/camel/spring/boot/SupervisingRouteControllerConfiguration.java
----------------------------------------------------------------------
diff --git a/components/camel-spring-boot2/src/main/java/org/apache/camel/spring/boot/SupervisingRouteControllerConfiguration.java b/components/camel-spring-boot2/src/main/java/org/apache/camel/spring/boot/SupervisingRouteControllerConfiguration.java
new file mode 100644
index 0000000..1c4096d
--- /dev/null
+++ b/components/camel-spring-boot2/src/main/java/org/apache/camel/spring/boot/SupervisingRouteControllerConfiguration.java
@@ -0,0 +1,179 @@
+/**
+ * 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 {
+ /**
+ * Global option to enable/disable this ${@link org.apache.camel.spi.RouteController}, default is false.
+ */
+ private boolean enabled;
+
+ /**
+ * Set the amount of time the route controller should wait before to start
+ * the routes after the camel context is started or after the route is
+ * initialized if the route is created after the camel context is started.
+ */
+ private String initialDelay;
+
+ /**
+ * The default back-off configuration, back-off configuration for routes inherits from this default.
+ */
+ private BackOffConfiguration defaultBackOff = new BackOffConfiguration();
+
+ /**
+ * Routes configuration.
+ */
+ private Map<String, RouteConfiguration> routes = new HashMap<>();
+
+ public boolean isEnabled() {
+ return enabled;
+ }
+
+ public void setEnabled(boolean enabled) {
+ this.enabled = enabled;
+ }
+
+ public String getInitialDelay() {
+ return initialDelay;
+ }
+
+ public void setInitialDelay(String initialDelay) {
+ this.initialDelay = initialDelay;
+ }
+
+ public BackOffConfiguration getDefaultBackOff() {
+ return defaultBackOff;
+ }
+
+ public Map<String, RouteConfiguration> getRoutes() {
+ return routes;
+ }
+
+ // *****************************************
+ // Configuration Classes
+ // *****************************************
+
+ public static class RouteConfiguration {
+ /**
+ * Control if the route should be supervised or not, default is true.
+ */
+ private boolean supervise = true;
+
+ /**
+ * The back-off configuration from this route, inherits from default back-off
+ */
+ private BackOffConfiguration backOff;
+
+ public boolean isSupervised() {
+ return supervise;
+ }
+
+ public void setSupervise(boolean supervise) {
+ this.supervise = supervise;
+ }
+
+ public BackOffConfiguration getBackOff() {
+ return backOff;
+ }
+
+ public void setBackOff(BackOffConfiguration backOff) {
+ this.backOff = backOff;
+ }
+ }
+
+ public static class BackOffConfiguration {
+ /**
+ * The delay to wait before retry the operation.
+ *
+ * You can also specify time values using units, such as 60s (60 seconds),
+ * 5m30s (5 minutes and 30 seconds), and 1h (1 hour).
+ */
+ private String delay;
+
+ /**
+ * The maximum back-off time.
+ *
+ * You can also specify time values using units, such as 60s (60 seconds),
+ * 5m30s (5 minutes and 30 seconds), and 1h (1 hour).
+ */
+ private String maxDelay;
+
+ /**
+ * The maximum elapsed time after which the back-off is exhausted.
+ *
+ * You can also specify time values using units, such as 60s (60 seconds),
+ * 5m30s (5 minutes and 30 seconds), and 1h (1 hour).
+ */
+ private String maxElapsedTime;
+
+ /**
+ * The maximum number of attempts after which the back-off is exhausted.
+ */
+ private Long maxAttempts;
+
+ /**
+ * The value to multiply the current interval by for each retry attempt.
+ */
+ 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/cb70f538/components/camel-spring-boot2/src/main/java/org/apache/camel/spring/boot/TypeConversionConfiguration.java
----------------------------------------------------------------------
diff --git a/components/camel-spring-boot2/src/main/java/org/apache/camel/spring/boot/TypeConversionConfiguration.java b/components/camel-spring-boot2/src/main/java/org/apache/camel/spring/boot/TypeConversionConfiguration.java
new file mode 100644
index 0000000..f49cb31
--- /dev/null
+++ b/components/camel-spring-boot2/src/main/java/org/apache/camel/spring/boot/TypeConversionConfiguration.java
@@ -0,0 +1,64 @@
+/**
+ * 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 static java.util.Arrays.asList;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.TypeConverter;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.core.convert.ConversionService;
+import org.springframework.core.convert.converter.Converter;
+import org.springframework.core.convert.support.DefaultConversionService;
+
+@Configuration
+@ConditionalOnProperty(value = "camel.springboot.typeConversion", matchIfMissing = true)
+public class TypeConversionConfiguration {
+
+ // We explicitly declare the destroyMethod to be "" as the Spring @Bean
+ // annotation defaults to AbstractBeanDefinition.INFER_METHOD otherwise
+ // and in that case ShutdownableService::shutdown/Service::close
+ // (BaseTypeConverterRegistry extends ServiceSupport) would be used for
+ // bean destruction. And we want Camel to handle the lifecycle.
+ @Bean(destroyMethod = "")
+ // Camel handles the lifecycle of this bean
+ TypeConverter typeConverter(CamelContext camelContext) {
+ return camelContext.getTypeConverter();
+ }
+
+ @Bean
+ SpringTypeConverter springTypeConverter(CamelContext camelContext, ConversionService[] conversionServices) {
+ SpringTypeConverter springTypeConverter = new SpringTypeConverter(asList(conversionServices));
+ camelContext.getTypeConverterRegistry().addFallbackTypeConverter(springTypeConverter, true);
+ return springTypeConverter;
+ }
+
+ @ConditionalOnMissingBean
+ @Bean
+ ConversionService defaultCamelConversionService(ApplicationContext applicationContext) {
+ DefaultConversionService service = new DefaultConversionService();
+ for (Converter converter : applicationContext.getBeansOfType(Converter.class).values()) {
+ service.addConverter(converter);
+ }
+ return service;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/cb70f538/components/camel-spring-boot2/src/main/java/org/apache/camel/spring/boot/actuate/endpoint/CamelRouteControllerEndpoint.java
----------------------------------------------------------------------
diff --git a/components/camel-spring-boot2/src/main/java/org/apache/camel/spring/boot/actuate/endpoint/CamelRouteControllerEndpoint.java b/components/camel-spring-boot2/src/main/java/org/apache/camel/spring/boot/actuate/endpoint/CamelRouteControllerEndpoint.java
new file mode 100644
index 0000000..357a8d0
--- /dev/null
+++ b/components/camel-spring-boot2/src/main/java/org/apache/camel/spring/boot/actuate/endpoint/CamelRouteControllerEndpoint.java
@@ -0,0 +1,60 @@
+/**
+ * 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 java.util.Collections;
+import java.util.List;
+import java.util.stream.Collectors;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Route;
+import org.apache.camel.spi.RouteController;
+import org.springframework.boot.actuate.endpoint.AbstractEndpoint;
+import org.springframework.boot.actuate.endpoint.Endpoint;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+
+/**
+ * {@link Endpoint} to expose {@link RouteController} information.
+ */
+@ConfigurationProperties(prefix = "endpoints." + CamelRouteControllerEndpoint.ENDPOINT_ID)
+public class CamelRouteControllerEndpoint extends AbstractEndpoint<List<String>> {
+
+ public static final String ENDPOINT_ID = "camelroutecontroller";
+
+ private CamelContext camelContext;
+
+ public CamelRouteControllerEndpoint(CamelContext camelContext) {
+ super(ENDPOINT_ID);
+ this.camelContext = camelContext;
+ // is enabled by default
+ this.setEnabled(true);
+ }
+
+ @Override
+ public List<String> invoke() {
+ RouteController controller = camelContext.getRouteController();
+
+ if (controller != null) {
+ return controller.getControlledRoutes().stream()
+ .map(Route::getId)
+ .collect(Collectors.toList());
+ }
+
+ return Collections.emptyList();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/cb70f538/components/camel-spring-boot2/src/main/java/org/apache/camel/spring/boot/actuate/endpoint/CamelRouteControllerEndpointAutoConfiguration.java
----------------------------------------------------------------------
diff --git a/components/camel-spring-boot2/src/main/java/org/apache/camel/spring/boot/actuate/endpoint/CamelRouteControllerEndpointAutoConfiguration.java b/components/camel-spring-boot2/src/main/java/org/apache/camel/spring/boot/actuate/endpoint/CamelRouteControllerEndpointAutoConfiguration.java
new file mode 100644
index 0000000..2c09427
--- /dev/null
+++ b/components/camel-spring-boot2/src/main/java/org/apache/camel/spring/boot/actuate/endpoint/CamelRouteControllerEndpointAutoConfiguration.java
@@ -0,0 +1,49 @@
+/**
+ * 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.apache.camel.CamelContext;
+import org.apache.camel.spring.boot.CamelAutoConfiguration;
+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;
+
+/**
+ * Auto configuration for the {@link CamelRouteControllerEndpoint}.
+ */
+@Configuration
+@ConditionalOnClass({CamelRouteControllerEndpoint.class})
+@ConditionalOnBean(CamelAutoConfiguration.class)
+@AutoConfigureAfter(CamelAutoConfiguration.class)
+public class CamelRouteControllerEndpointAutoConfiguration {
+ @Bean
+ @ConditionalOnClass(CamelContext.class)
+ @ConditionalOnMissingBean
+ public CamelRouteControllerEndpoint routeControllerEndpoint(CamelContext camelContext) {
+ return new CamelRouteControllerEndpoint(camelContext);
+ }
+
+ @Bean
+ @ConditionalOnClass(CamelContext.class)
+ @ConditionalOnMissingBean
+ public CamelRouteControllerMvcEndpoint routeControllerMvcEndpoint(CamelRouteControllerEndpoint delegate) {
+ return new CamelRouteControllerMvcEndpoint(delegate);
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/cb70f538/components/camel-spring-boot2/src/main/java/org/apache/camel/spring/boot/actuate/endpoint/CamelRouteControllerMvcEndpoint.java
----------------------------------------------------------------------
diff --git a/components/camel-spring-boot2/src/main/java/org/apache/camel/spring/boot/actuate/endpoint/CamelRouteControllerMvcEndpoint.java b/components/camel-spring-boot2/src/main/java/org/apache/camel/spring/boot/actuate/endpoint/CamelRouteControllerMvcEndpoint.java
new file mode 100644
index 0000000..cbde49e
--- /dev/null
+++ b/components/camel-spring-boot2/src/main/java/org/apache/camel/spring/boot/actuate/endpoint/CamelRouteControllerMvcEndpoint.java
@@ -0,0 +1,79 @@
+/**
+ * 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 java.util.function.Supplier;
+
+import org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter;
+import org.springframework.boot.actuate.endpoint.mvc.MvcEndpoint;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.http.HttpStatus;
+import org.springframework.web.bind.annotation.ResponseStatus;
+
+/**
+ * Adapter to expose {@link CamelRouteControllerEndpoint} as an {@link MvcEndpoint}.
+ */
+@ConfigurationProperties(prefix = "endpoints." + CamelRouteControllerEndpoint.ENDPOINT_ID)
+public class CamelRouteControllerMvcEndpoint extends EndpointMvcAdapter {
+
+ /**
+ * Default path
+ */
+ public static final String PATH = "/camel/route-controller";
+
+ private final CamelRouteControllerEndpoint delegate;
+
+ public CamelRouteControllerMvcEndpoint(CamelRouteControllerEndpoint delegate) {
+ super(delegate);
+
+ this.setPath(PATH);
+ this.delegate = delegate;
+ }
+
+ // ********************************************
+ // Endpoints
+ // ********************************************
+
+ // ********************************************
+ // Helpers
+ // ********************************************
+
+ private Object doIfEnabled(Supplier<Object> supplier) {
+ if (!delegate.isEnabled()) {
+ return getDisabledResponse();
+ }
+
+ return supplier.get();
+ }
+
+ @SuppressWarnings("serial")
+ @ResponseStatus(value = HttpStatus.INTERNAL_SERVER_ERROR)
+ public static class GenericException extends RuntimeException {
+ public GenericException(String message, Throwable cause) {
+ super(message, cause);
+
+ }
+ }
+
+ @SuppressWarnings("serial")
+ @ResponseStatus(value = HttpStatus.NOT_FOUND, reason = "No such route")
+ public static class NoSuchRouteException extends RuntimeException {
+ public NoSuchRouteException(String message) {
+ super(message);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/cb70f538/components/camel-spring-boot2/src/main/java/org/apache/camel/spring/boot/actuate/endpoint/CamelRoutesEndpoint.java
----------------------------------------------------------------------
diff --git a/components/camel-spring-boot2/src/main/java/org/apache/camel/spring/boot/actuate/endpoint/CamelRoutesEndpoint.java b/components/camel-spring-boot2/src/main/java/org/apache/camel/spring/boot/actuate/endpoint/CamelRoutesEndpoint.java
new file mode 100644
index 0000000..af867ae
--- /dev/null
+++ b/components/camel-spring-boot2/src/main/java/org/apache/camel/spring/boot/actuate/endpoint/CamelRoutesEndpoint.java
@@ -0,0 +1,377 @@
+/**
+ * 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 java.util.Date;
+import java.util.List;
+import java.util.Optional;
+import java.util.concurrent.TimeUnit;
+import java.util.stream.Collectors;
+
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.annotation.JsonPropertyOrder;
+import org.apache.camel.CamelContext;
+import org.apache.camel.Route;
+import org.apache.camel.StatefulService;
+import org.apache.camel.api.management.mbean.ManagedRouteMBean;
+import org.apache.camel.spi.RouteError;
+import org.apache.camel.spring.boot.actuate.endpoint.CamelRoutesEndpoint.RouteEndpointInfo;
+import org.springframework.boot.actuate.endpoint.AbstractEndpoint;
+import org.springframework.boot.actuate.endpoint.Endpoint;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+
+/**
+ * {@link Endpoint} to expose {@link org.apache.camel.Route} information.
+ */
+@ConfigurationProperties(prefix = "endpoints." + CamelRoutesEndpoint.ENDPOINT_ID)
+public class CamelRoutesEndpoint extends AbstractEndpoint<List<RouteEndpointInfo>> {
+
+ public static final String ENDPOINT_ID = "camelroutes";
+
+ private CamelContext camelContext;
+
+ public CamelRoutesEndpoint(CamelContext camelContext) {
+ super(ENDPOINT_ID);
+ this.camelContext = camelContext;
+ // is enabled by default
+ this.setEnabled(true);
+ }
+
+ @Override
+ public List<RouteEndpointInfo> invoke() {
+ return getRoutesInfo();
+ }
+
+ public RouteEndpointInfo getRouteInfo(String id) {
+ Route route = camelContext.getRoute(id);
+ if (route != null) {
+ return new RouteEndpointInfo(route);
+ }
+
+ return null;
+ }
+
+ public List<RouteEndpointInfo> getRoutesInfo() {
+ return camelContext.getRoutes().stream()
+ .map(RouteEndpointInfo::new)
+ .collect(Collectors.toList());
+ }
+
+ public RouteDetailsEndpointInfo getRouteDetailsInfo(String id) {
+ Route route = camelContext.getRoute(id);
+ if (route != null) {
+ return new RouteDetailsEndpointInfo(camelContext, route);
+ }
+
+ return null;
+ }
+
+ public void startRoute(String id) throws Exception {
+ camelContext.getRouteController().startRoute(id);
+ }
+
+ public void resetRoute(String id) throws Exception {
+ ManagedRouteMBean managedRouteMBean = camelContext.getManagedRoute(id, ManagedRouteMBean.class);
+ if (managedRouteMBean != null) {
+ managedRouteMBean.reset(true);
+ }
+ }
+
+ public void stopRoute(String id, Optional<Long> timeout, Optional<TimeUnit> timeUnit, Optional<Boolean> abortAfterTimeout) throws Exception {
+ if (timeout.isPresent()) {
+ camelContext.getRouteController().stopRoute(id, timeout.get(), timeUnit.orElse(TimeUnit.SECONDS), abortAfterTimeout.orElse(Boolean.TRUE));
+ } else {
+ camelContext.getRouteController().stopRoute(id);
+ }
+ }
+
+ public void suspendRoute(String id, Optional<Long> timeout, Optional<TimeUnit> timeUnit) throws Exception {
+ if (timeout.isPresent()) {
+ camelContext.getRouteController().suspendRoute(id, timeout.get(), timeUnit.orElse(TimeUnit.SECONDS));
+ } else {
+ camelContext.getRouteController().suspendRoute(id);
+ }
+ }
+
+ public void resumeRoute(String id) throws Exception {
+ camelContext.getRouteController().resumeRoute(id);
+ }
+
+ /**
+ * Container for exposing {@link org.apache.camel.Route} information as JSON.
+ */
+ @JsonPropertyOrder({"id", "description", "uptime", "uptimeMillis"})
+ @JsonInclude(JsonInclude.Include.NON_EMPTY)
+ public static class RouteEndpointInfo {
+
+ private final String id;
+
+ private final String description;
+
+ private final String uptime;
+
+ private final long uptimeMillis;
+
+ private final String status;
+
+ public RouteEndpointInfo(Route route) {
+ this.id = route.getId();
+ this.description = route.getDescription();
+ this.uptime = route.getUptime();
+ this.uptimeMillis = route.getUptimeMillis();
+
+ if (route instanceof StatefulService) {
+ this.status = ((StatefulService) route).getStatus().name();
+ } else {
+ this.status = null;
+ }
+ }
+
+ public String getId() {
+ return id;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public String getUptime() {
+ return uptime;
+ }
+
+ public long getUptimeMillis() {
+ return uptimeMillis;
+ }
+
+ public String getStatus() {
+ return status;
+ }
+ }
+
+ /**
+ * Container for exposing {@link org.apache.camel.Route} information
+ * with route details as JSON. Route details are retrieved from JMX.
+ */
+ public static class RouteDetailsEndpointInfo extends RouteEndpointInfo {
+
+ @JsonProperty("details")
+ private RouteDetails routeDetails;
+
+ public RouteDetailsEndpointInfo(final CamelContext camelContext, final Route route) {
+ super(route);
+
+ if (camelContext.getManagementStrategy().getManagementAgent() != null) {
+ this.routeDetails = new RouteDetails(camelContext.getManagedRoute(route.getId(), ManagedRouteMBean.class));
+ }
+ }
+
+ @JsonInclude(JsonInclude.Include.NON_EMPTY)
+ static class RouteDetails {
+
+ private long deltaProcessingTime;
+
+ private long exchangesInflight;
+
+ private long exchangesTotal;
+
+ private long externalRedeliveries;
+
+ private long failuresHandled;
+
+ private String firstExchangeCompletedExchangeId;
+
+ private Date firstExchangeCompletedTimestamp;
+
+ private String firstExchangeFailureExchangeId;
+
+ private Date firstExchangeFailureTimestamp;
+
+ private String lastExchangeCompletedExchangeId;
+
+ private Date lastExchangeCompletedTimestamp;
+
+ private String lastExchangeFailureExchangeId;
+
+ private Date lastExchangeFailureTimestamp;
+
+ private long lastProcessingTime;
+
+ private String load01;
+
+ private String load05;
+
+ private String load15;
+
+ private long maxProcessingTime;
+
+ private long meanProcessingTime;
+
+ private long minProcessingTime;
+
+ private Long oldestInflightDuration;
+
+ private String oldestInflightExchangeId;
+
+ private long redeliveries;
+
+ private long totalProcessingTime;
+
+ private RouteError lastError;
+
+ private boolean hasRouteController;
+
+ RouteDetails(ManagedRouteMBean managedRoute) {
+ try {
+ this.deltaProcessingTime = managedRoute.getDeltaProcessingTime();
+ this.exchangesInflight = managedRoute.getExchangesInflight();
+ this.exchangesTotal = managedRoute.getExchangesTotal();
+ this.externalRedeliveries = managedRoute.getExternalRedeliveries();
+ this.failuresHandled = managedRoute.getFailuresHandled();
+ this.firstExchangeCompletedExchangeId = managedRoute.getFirstExchangeCompletedExchangeId();
+ this.firstExchangeCompletedTimestamp = managedRoute.getFirstExchangeCompletedTimestamp();
+ this.firstExchangeFailureExchangeId = managedRoute.getFirstExchangeFailureExchangeId();
+ this.firstExchangeFailureTimestamp = managedRoute.getFirstExchangeFailureTimestamp();
+ this.lastExchangeCompletedExchangeId = managedRoute.getLastExchangeCompletedExchangeId();
+ this.lastExchangeCompletedTimestamp = managedRoute.getLastExchangeCompletedTimestamp();
+ this.lastExchangeFailureExchangeId = managedRoute.getLastExchangeFailureExchangeId();
+ this.lastExchangeFailureTimestamp = managedRoute.getLastExchangeFailureTimestamp();
+ this.lastProcessingTime = managedRoute.getLastProcessingTime();
+ this.load01 = managedRoute.getLoad01();
+ this.load05 = managedRoute.getLoad05();
+ this.load15 = managedRoute.getLoad15();
+ this.maxProcessingTime = managedRoute.getMaxProcessingTime();
+ this.meanProcessingTime = managedRoute.getMeanProcessingTime();
+ this.minProcessingTime = managedRoute.getMinProcessingTime();
+ this.oldestInflightDuration = managedRoute.getOldestInflightDuration();
+ this.oldestInflightExchangeId = managedRoute.getOldestInflightExchangeId();
+ this.redeliveries = managedRoute.getRedeliveries();
+ this.totalProcessingTime = managedRoute.getTotalProcessingTime();
+ this.lastError = managedRoute.getLastError();
+ this.hasRouteController = managedRoute.getHasRouteController();
+ } catch (Exception e) {
+ // Ignore
+ }
+ }
+
+ public long getDeltaProcessingTime() {
+ return deltaProcessingTime;
+ }
+
+ public long getExchangesInflight() {
+ return exchangesInflight;
+ }
+
+ public long getExchangesTotal() {
+ return exchangesTotal;
+ }
+
+ public long getExternalRedeliveries() {
+ return externalRedeliveries;
+ }
+
+ public long getFailuresHandled() {
+ return failuresHandled;
+ }
+
+ public String getFirstExchangeCompletedExchangeId() {
+ return firstExchangeCompletedExchangeId;
+ }
+
+ public Date getFirstExchangeCompletedTimestamp() {
+ return firstExchangeCompletedTimestamp;
+ }
+
+ public String getFirstExchangeFailureExchangeId() {
+ return firstExchangeFailureExchangeId;
+ }
+
+ public Date getFirstExchangeFailureTimestamp() {
+ return firstExchangeFailureTimestamp;
+ }
+
+ public String getLastExchangeCompletedExchangeId() {
+ return lastExchangeCompletedExchangeId;
+ }
+
+ public Date getLastExchangeCompletedTimestamp() {
+ return lastExchangeCompletedTimestamp;
+ }
+
+ public String getLastExchangeFailureExchangeId() {
+ return lastExchangeFailureExchangeId;
+ }
+
+ public Date getLastExchangeFailureTimestamp() {
+ return lastExchangeFailureTimestamp;
+ }
+
+ public long getLastProcessingTime() {
+ return lastProcessingTime;
+ }
+
+ public String getLoad01() {
+ return load01;
+ }
+
+ public String getLoad05() {
+ return load05;
+ }
+
+ public String getLoad15() {
+ return load15;
+ }
+
+ public long getMaxProcessingTime() {
+ return maxProcessingTime;
+ }
+
+ public long getMeanProcessingTime() {
+ return meanProcessingTime;
+ }
+
+ public long getMinProcessingTime() {
+ return minProcessingTime;
+ }
+
+ public Long getOldestInflightDuration() {
+ return oldestInflightDuration;
+ }
+
+ public String getOldestInflightExchangeId() {
+ return oldestInflightExchangeId;
+ }
+
+ public long getRedeliveries() {
+ return redeliveries;
+ }
+
+ public long getTotalProcessingTime() {
+ return totalProcessingTime;
+ }
+
+ public RouteError getLastError() {
+ return lastError;
+ }
+
+ public boolean getHasRouteController() {
+ return hasRouteController;
+ }
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/cb70f538/components/camel-spring-boot2/src/main/java/org/apache/camel/spring/boot/actuate/endpoint/CamelRoutesEndpointAutoConfiguration.java
----------------------------------------------------------------------
diff --git a/components/camel-spring-boot2/src/main/java/org/apache/camel/spring/boot/actuate/endpoint/CamelRoutesEndpointAutoConfiguration.java b/components/camel-spring-boot2/src/main/java/org/apache/camel/spring/boot/actuate/endpoint/CamelRoutesEndpointAutoConfiguration.java
new file mode 100644
index 0000000..2425359
--- /dev/null
+++ b/components/camel-spring-boot2/src/main/java/org/apache/camel/spring/boot/actuate/endpoint/CamelRoutesEndpointAutoConfiguration.java
@@ -0,0 +1,49 @@
+/**
+ * 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.apache.camel.CamelContext;
+import org.apache.camel.spring.boot.CamelAutoConfiguration;
+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;
+
+/**
+ * Auto configuration for the {@link CamelRoutesEndpoint}.
+ */
+@Configuration
+@ConditionalOnClass({CamelRoutesEndpoint.class})
+@ConditionalOnBean(CamelAutoConfiguration.class)
+@AutoConfigureAfter(CamelAutoConfiguration.class)
+public class CamelRoutesEndpointAutoConfiguration {
+ @Bean
+ @ConditionalOnClass(CamelContext.class)
+ @ConditionalOnMissingBean
+ public CamelRoutesEndpoint camelEndpoint(CamelContext camelContext) {
+ return new CamelRoutesEndpoint(camelContext);
+ }
+
+ @Bean
+ @ConditionalOnClass(CamelContext.class)
+ @ConditionalOnMissingBean
+ public CamelRoutesMvcEndpoint camelMvcEndpoint(CamelRoutesEndpoint delegate) {
+ return new CamelRoutesMvcEndpoint(delegate);
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/cb70f538/components/camel-spring-boot2/src/main/java/org/apache/camel/spring/boot/actuate/endpoint/CamelRoutesMvcEndpoint.java
----------------------------------------------------------------------
diff --git a/components/camel-spring-boot2/src/main/java/org/apache/camel/spring/boot/actuate/endpoint/CamelRoutesMvcEndpoint.java b/components/camel-spring-boot2/src/main/java/org/apache/camel/spring/boot/actuate/endpoint/CamelRoutesMvcEndpoint.java
new file mode 100644
index 0000000..cf4836e
--- /dev/null
+++ b/components/camel-spring-boot2/src/main/java/org/apache/camel/spring/boot/actuate/endpoint/CamelRoutesMvcEndpoint.java
@@ -0,0 +1,247 @@
+/**
+ * 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 java.util.Optional;
+import java.util.concurrent.TimeUnit;
+import java.util.function.Supplier;
+
+import org.springframework.boot.actuate.endpoint.mvc.ActuatorMediaTypes;
+import org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter;
+import org.springframework.boot.actuate.endpoint.mvc.MvcEndpoint;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.MediaType;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestAttribute;
+import org.springframework.web.bind.annotation.ResponseBody;
+import org.springframework.web.bind.annotation.ResponseStatus;
+
+/**
+ * Adapter to expose {@link CamelRoutesEndpoint} as an {@link MvcEndpoint}.
+ */
+@ConfigurationProperties(prefix = "endpoints." + CamelRoutesEndpoint.ENDPOINT_ID)
+public class CamelRoutesMvcEndpoint extends EndpointMvcAdapter {
+
+ /**
+ * Default path
+ */
+ public static final String PATH = "/camel/routes";
+
+ private final CamelRoutesEndpoint delegate;
+
+ public CamelRoutesMvcEndpoint(CamelRoutesEndpoint delegate) {
+ super(delegate);
+
+ this.setPath(PATH);
+ this.delegate = delegate;
+ }
+
+ // ********************************************
+ // Endpoints
+ // ********************************************
+
+ @ResponseBody
+ @GetMapping(
+ value = "/{id}/detail",
+ produces = {
+ ActuatorMediaTypes.APPLICATION_ACTUATOR_V1_JSON_VALUE,
+ MediaType.APPLICATION_JSON_VALUE
+ }
+ )
+ public Object detail(
+ @PathVariable String id) {
+
+ return doIfEnabled(() -> {
+ Object result = delegate.getRouteDetailsInfo(id);
+ if (result == null) {
+ throw new NoSuchRouteException("No such route " + id);
+ }
+
+ return result;
+ });
+ }
+
+ @ResponseBody
+ @GetMapping(
+ value = "/{id}/info",
+ produces = {
+ ActuatorMediaTypes.APPLICATION_ACTUATOR_V1_JSON_VALUE,
+ MediaType.APPLICATION_JSON_VALUE
+ }
+ )
+ public Object info(
+ @PathVariable String id) {
+
+ return doIfEnabled(() -> {
+ Object result = delegate.getRouteInfo(id);
+ if (result == null) {
+ throw new NoSuchRouteException("No such route " + id);
+ }
+
+ return result;
+ });
+ }
+
+ @ResponseBody
+ @PostMapping(
+ value = "/{id}/stop",
+ produces = {
+ ActuatorMediaTypes.APPLICATION_ACTUATOR_V1_JSON_VALUE,
+ MediaType.APPLICATION_JSON_VALUE
+ }
+ )
+ public Object stop(
+ @PathVariable String id,
+ @RequestAttribute(required = false) Long timeout,
+ @RequestAttribute(required = false) Boolean abortAfterTimeout) {
+
+ return doIfEnabled(() -> {
+ try {
+ delegate.stopRoute(
+ id,
+ Optional.ofNullable(timeout),
+ Optional.of(TimeUnit.SECONDS),
+ Optional.ofNullable(abortAfterTimeout)
+ );
+ } catch (Exception e) {
+ throw new GenericException("Error stopping route " + id, e);
+ }
+
+ return ResponseEntity.ok().build();
+ });
+ }
+
+ @ResponseBody
+ @PostMapping(
+ value = "/{id}/start",
+ produces = {
+ ActuatorMediaTypes.APPLICATION_ACTUATOR_V1_JSON_VALUE,
+ MediaType.APPLICATION_JSON_VALUE
+ }
+ )
+ public Object start(
+ @PathVariable String id) {
+
+ return doIfEnabled(() -> {
+ try {
+ delegate.startRoute(id);
+ } catch (Exception e) {
+ throw new GenericException("Error starting route " + id, e);
+ }
+
+ return ResponseEntity.ok().build();
+ });
+ }
+
+ @ResponseBody
+ @PostMapping(value = "/{id}/reset", produces = {ActuatorMediaTypes.APPLICATION_ACTUATOR_V1_JSON_VALUE, MediaType.APPLICATION_JSON_VALUE})
+ public Object reset(@PathVariable String id) {
+
+ return doIfEnabled(() -> {
+ try {
+ delegate.resetRoute(id);
+ } catch (Exception e) {
+ throw new GenericException("Error resetting route stats " + id, e);
+ }
+
+ return ResponseEntity.ok().build();
+ });
+ }
+
+
+ @ResponseBody
+ @PostMapping(
+ value = "/{id}/suspend",
+ produces = {
+ ActuatorMediaTypes.APPLICATION_ACTUATOR_V1_JSON_VALUE,
+ MediaType.APPLICATION_JSON_VALUE
+ }
+ )
+ public Object suspend(
+ @PathVariable String id,
+ @RequestAttribute(required = false) Long timeout) {
+
+ return doIfEnabled(() -> {
+ try {
+ delegate.suspendRoute(
+ id,
+ Optional.ofNullable(timeout),
+ Optional.of(TimeUnit.SECONDS)
+ );
+ } catch (Exception e) {
+ throw new GenericException("Error suspending route " + id, e);
+ }
+
+ return ResponseEntity.ok().build();
+ });
+ }
+
+ @ResponseBody
+ @PostMapping(
+ value = "/{id}/resume",
+ produces = {
+ ActuatorMediaTypes.APPLICATION_ACTUATOR_V1_JSON_VALUE,
+ MediaType.APPLICATION_JSON_VALUE
+ }
+ )
+ public Object resume(
+ @PathVariable String id) {
+
+ return doIfEnabled(() -> {
+ try {
+ delegate.resumeRoute(id);
+ } catch (Exception e) {
+ throw new GenericException("Error resuming route " + id, e);
+ }
+
+ return ResponseEntity.ok().build();
+ });
+ }
+
+ // ********************************************
+ // Helpers
+ // ********************************************
+
+ private Object doIfEnabled(Supplier<Object> supplier) {
+ if (!delegate.isEnabled()) {
+ return getDisabledResponse();
+ }
+
+ return supplier.get();
+ }
+
+ @SuppressWarnings("serial")
+ @ResponseStatus(value = HttpStatus.INTERNAL_SERVER_ERROR)
+ public static class GenericException extends RuntimeException {
+ public GenericException(String message, Throwable cause) {
+ super(message, cause);
+
+ }
+ }
+
+ @SuppressWarnings("serial")
+ @ResponseStatus(value = HttpStatus.NOT_FOUND, reason = "No such route")
+ public static class NoSuchRouteException extends RuntimeException {
+ public NoSuchRouteException(String message) {
+ super(message);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/cb70f538/components/camel-spring-boot2/src/main/java/org/apache/camel/spring/boot/actuate/health/CamelHealthAutoConfiguration.java
----------------------------------------------------------------------
diff --git a/components/camel-spring-boot2/src/main/java/org/apache/camel/spring/boot/actuate/health/CamelHealthAutoConfiguration.java b/components/camel-spring-boot2/src/main/java/org/apache/camel/spring/boot/actuate/health/CamelHealthAutoConfiguration.java
new file mode 100644
index 0000000..3b59f26
--- /dev/null
+++ b/components/camel-spring-boot2/src/main/java/org/apache/camel/spring/boot/actuate/health/CamelHealthAutoConfiguration.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.health;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.spring.boot.CamelAutoConfiguration;
+import org.springframework.boot.actuate.health.HealthIndicator;
+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({HealthIndicator.class})
+@ConditionalOnBean(CamelAutoConfiguration.class)
+@AutoConfigureAfter(CamelAutoConfiguration.class)
+public class CamelHealthAutoConfiguration {
+
+ @ConditionalOnClass({CamelContext.class})
+ @ConditionalOnMissingBean(CamelHealthIndicator.class)
+ protected static class CamelHealthIndicatorInitializer {
+
+ @Bean
+ public HealthIndicator camelHealthIndicator(CamelContext camelContext) {
+ return new CamelHealthIndicator(camelContext);
+ }
+
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/cb70f538/components/camel-spring-boot2/src/main/java/org/apache/camel/spring/boot/actuate/health/CamelHealthIndicator.java
----------------------------------------------------------------------
diff --git a/components/camel-spring-boot2/src/main/java/org/apache/camel/spring/boot/actuate/health/CamelHealthIndicator.java b/components/camel-spring-boot2/src/main/java/org/apache/camel/spring/boot/actuate/health/CamelHealthIndicator.java
new file mode 100644
index 0000000..1968068
--- /dev/null
+++ b/components/camel-spring-boot2/src/main/java/org/apache/camel/spring/boot/actuate/health/CamelHealthIndicator.java
@@ -0,0 +1,52 @@
+/**
+ * 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.health;
+
+import org.apache.camel.CamelContext;
+import org.springframework.boot.actuate.health.AbstractHealthIndicator;
+import org.springframework.boot.actuate.health.Health;
+import org.springframework.boot.actuate.health.HealthIndicator;
+
+/**
+ * Camel {@link HealthIndicator}.
+ */
+public class CamelHealthIndicator extends AbstractHealthIndicator {
+
+ private CamelContext camelContext;
+
+ public CamelHealthIndicator(CamelContext camelContext) {
+ this.camelContext = camelContext;
+ }
+
+ @Override
+ protected void doHealthCheck(Health.Builder builder) throws Exception {
+ if (camelContext == null) {
+ builder.unknown();
+ } else {
+ builder.withDetail("name", camelContext.getName());
+ builder.withDetail("version", camelContext.getVersion());
+ builder.withDetail("contextStatus", camelContext.getStatus().name());
+ if (camelContext.getStatus().isStarted()) {
+ builder.up();
+ } else if (camelContext.getStatus().isStopped()) {
+ builder.down();
+ } else {
+ builder.unknown();
+ }
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/cb70f538/components/camel-spring-boot2/src/main/java/org/apache/camel/spring/boot/cloud/CamelCloudAutoConfiguration.java
----------------------------------------------------------------------
diff --git a/components/camel-spring-boot2/src/main/java/org/apache/camel/spring/boot/cloud/CamelCloudAutoConfiguration.java b/components/camel-spring-boot2/src/main/java/org/apache/camel/spring/boot/cloud/CamelCloudAutoConfiguration.java
new file mode 100644
index 0000000..f565769
--- /dev/null
+++ b/components/camel-spring-boot2/src/main/java/org/apache/camel/spring/boot/cloud/CamelCloudAutoConfiguration.java
@@ -0,0 +1,30 @@
+/**
+ * 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.cloud;
+
+import org.apache.camel.spring.boot.CamelAutoConfiguration;
+import org.springframework.boot.autoconfigure.AutoConfigureAfter;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.context.annotation.Configuration;
+
+@Configuration
+@ConditionalOnBean(CamelAutoConfiguration.class)
+@AutoConfigureAfter(CamelAutoConfiguration.class)
+@ConditionalOnProperty(value = "camel.cloud.enabled", matchIfMissing = true)
+public class CamelCloudAutoConfiguration {
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/cb70f538/components/camel-spring-boot2/src/main/java/org/apache/camel/spring/boot/cloud/CamelCloudConfigurationProperties.java
----------------------------------------------------------------------
diff --git a/components/camel-spring-boot2/src/main/java/org/apache/camel/spring/boot/cloud/CamelCloudConfigurationProperties.java b/components/camel-spring-boot2/src/main/java/org/apache/camel/spring/boot/cloud/CamelCloudConfigurationProperties.java
new file mode 100644
index 0000000..7fbd65d
--- /dev/null
+++ b/components/camel-spring-boot2/src/main/java/org/apache/camel/spring/boot/cloud/CamelCloudConfigurationProperties.java
@@ -0,0 +1,274 @@
+/**
+ * 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.cloud;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.camel.Expression;
+import org.apache.camel.cloud.ServiceLoadBalancer;
+import org.apache.camel.model.cloud.ServiceCallDefinitionConstants;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+
+@ConfigurationProperties(prefix = "camel.cloud")
+public class CamelCloudConfigurationProperties {
+ private boolean enabled = true;
+ private ServiceCall serviceCall = new ServiceCall();
+ private LoadBalancer loadBalancer = new LoadBalancer();
+ private ServiceDiscovery serviceDiscovery = new ServiceDiscovery();
+ private ServiceFilter serviceFilter = new ServiceFilter();
+ private ServiceChooser serviceChooser = new ServiceChooser();
+
+ public boolean isEnabled() {
+ return enabled;
+ }
+
+ public void setEnabled(boolean enabled) {
+ this.enabled = enabled;
+ }
+
+ public ServiceCall getServiceCall() {
+ return serviceCall;
+ }
+
+ public LoadBalancer getLoadBalancer() {
+ return loadBalancer;
+ }
+
+ public ServiceDiscovery getServiceDiscovery() {
+ return serviceDiscovery;
+ }
+
+ public ServiceFilter getServiceFilter() {
+ return serviceFilter;
+ }
+
+ public ServiceChooser getServiceChooser() {
+ return serviceChooser;
+ }
+
+ // *****************************************
+ // Service Call
+ // *****************************************
+
+ public class ServiceCall {
+ /**
+ * The uri of the endpoint to send to.
+ * The uri can be dynamic computed using the {@link org.apache.camel.language.simple.SimpleLanguage} expression.
+ */
+ private String uri;
+
+ /**
+ * The component to use.
+ */
+ private String component = ServiceCallDefinitionConstants.DEFAULT_COMPONENT;
+
+ /**
+ * A reference to the {@link org.apache.camel.cloud.ServiceDiscovery} to use.
+ */
+ private String serviceDiscovery;
+
+ /**
+ * A reference to the {@link org.apache.camel.cloud.ServiceFilter} to use.
+ */
+ private String serviceFilter;
+
+ /**
+ * A reference to the {@link org.apache.camel.cloud.ServiceChooser} to use.
+ */
+ private String serviceChooser;
+
+ /**
+ * A reference to the {@link ServiceLoadBalancer} to use.
+ */
+ private String loadBalancer;
+
+ /**
+ * The {@link Expression} to use.
+ */
+ private String expression;
+
+ /**
+ * The {@link Expression} language to use, default is ref
+ */
+ private String expressionLanguage = "ref";
+
+ public String getUri() {
+ return uri;
+ }
+
+ public void setUri(String uri) {
+ this.uri = uri;
+ }
+
+ public String getComponent() {
+ return component;
+ }
+
+ public void setComponent(String component) {
+ this.component = component;
+ }
+
+ public String getServiceDiscovery() {
+ return serviceDiscovery;
+ }
+
+ public void setServiceDiscovery(String serviceDiscovery) {
+ this.serviceDiscovery = serviceDiscovery;
+ }
+
+ public String getServiceFilter() {
+ return serviceFilter;
+ }
+
+ public void setServiceFilter(String serviceFilter) {
+ this.serviceFilter = serviceFilter;
+ }
+
+ public String getServiceChooser() {
+ return serviceChooser;
+ }
+
+ public void setServiceChooser(String serviceChooser) {
+ this.serviceChooser = serviceChooser;
+ }
+
+ public String getLoadBalancer() {
+ return loadBalancer;
+ }
+
+ public void setLoadBalancer(String loadBalancer) {
+ this.loadBalancer = loadBalancer;
+ }
+
+ public String getExpression() {
+ return expression;
+ }
+
+ public void setExpression(String expression) {
+ this.expression = expression;
+ }
+
+ public String getExpressionLanguage() {
+ return expressionLanguage;
+ }
+
+ public void setExpressionLanguage(String expressionLanguage) {
+ this.expressionLanguage = expressionLanguage;
+ }
+ }
+
+ // *****************************************
+ // Load Balancer
+ // *****************************************
+
+ public static class LoadBalancer {
+ private boolean enabled = true;
+
+ public boolean isEnabled() {
+ return enabled;
+ }
+
+ public void setEnabled(boolean enabled) {
+ this.enabled = enabled;
+ }
+ }
+
+ // *****************************************
+ // Service Discovery
+ // *****************************************
+
+ public static class ServiceDiscoveryConfiguration {
+ private Map<String, List<String>> services = new HashMap<>();
+ private String cacheTimeout;
+
+ public Map<String, List<String>> getServices() {
+ return services;
+ }
+
+ public String getCacheTimeout() {
+ return cacheTimeout;
+ }
+
+ public void setCacheTimeout(String cacheTimeout) {
+ this.cacheTimeout = cacheTimeout;
+ }
+ }
+
+ public static class ServiceDiscovery extends ServiceDiscoveryConfiguration {
+ private boolean enabled = true;
+ private Map<String, ServiceDiscoveryConfiguration> configurations = new HashMap<>();
+
+ public boolean isEnabled() {
+ return enabled;
+ }
+
+ public void setEnabled(boolean enabled) {
+ this.enabled = enabled;
+ }
+
+ public Map<String, ServiceDiscoveryConfiguration> getConfigurations() {
+ return configurations;
+ }
+ }
+
+ // *****************************************
+ // Service Filter
+ // *****************************************
+
+ public static class ServiceFilterConfiguration {
+ private Map<String, List<String>> blacklist = new HashMap<>();
+
+ public Map<String, List<String>> getBlacklist() {
+ return blacklist;
+ }
+ }
+
+ public static class ServiceFilter extends ServiceFilterConfiguration {
+ private boolean enabled = true;
+ private Map<String, ServiceFilterConfiguration> configurations = new HashMap<>();
+
+ public boolean isEnabled() {
+ return enabled;
+ }
+
+ public void setEnabled(boolean enabled) {
+ this.enabled = enabled;
+ }
+
+ public Map<String, ServiceFilterConfiguration> getConfigurations() {
+ return configurations;
+ }
+ }
+
+ // *****************************************
+ // Service Chooser
+ // *****************************************
+
+ public static class ServiceChooser {
+ private boolean enabled = true;
+
+ public boolean isEnabled() {
+ return enabled;
+ }
+
+ public void setEnabled(boolean enabled) {
+ this.enabled = enabled;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/cb70f538/components/camel-spring-boot2/src/main/java/org/apache/camel/spring/boot/cloud/CamelCloudServiceCallConfigurationAutoConfiguration.java
----------------------------------------------------------------------
diff --git a/components/camel-spring-boot2/src/main/java/org/apache/camel/spring/boot/cloud/CamelCloudServiceCallConfigurationAutoConfiguration.java b/components/camel-spring-boot2/src/main/java/org/apache/camel/spring/boot/cloud/CamelCloudServiceCallConfigurationAutoConfiguration.java
new file mode 100644
index 0000000..4da2718
--- /dev/null
+++ b/components/camel-spring-boot2/src/main/java/org/apache/camel/spring/boot/cloud/CamelCloudServiceCallConfigurationAutoConfiguration.java
@@ -0,0 +1,83 @@
+/**
+ * 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.cloud;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.model.cloud.ServiceCallConfigurationDefinition;
+import org.apache.camel.model.cloud.ServiceCallDefinitionConstants;
+import org.apache.camel.spi.Language;
+import org.apache.camel.spring.boot.util.GroupCondition;
+import org.apache.camel.util.ObjectHelper;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
+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.Conditional;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Lazy;
+
+@Configuration
+@ConditionalOnBean({ CamelCloudAutoConfiguration.class, CamelContext.class})
+@EnableConfigurationProperties(CamelCloudConfigurationProperties.class)
+@Conditional(CamelCloudServiceCallConfigurationAutoConfiguration.ServiceCallCondition.class)
+public class CamelCloudServiceCallConfigurationAutoConfiguration {
+ @Autowired
+ private CamelContext camelContext;
+ @Autowired
+ private CamelCloudConfigurationProperties configurationProperties;
+
+ @Lazy
+ @Bean(name = ServiceCallDefinitionConstants.DEFAULT_SERVICE_CALL_CONFIG_ID)
+ @ConditionalOnMissingBean(name = ServiceCallDefinitionConstants.DEFAULT_SERVICE_CALL_CONFIG_ID)
+ public ServiceCallConfigurationDefinition serviceCallConfiguration() throws Exception {
+ ServiceCallConfigurationDefinition definition = new ServiceCallConfigurationDefinition();
+ ObjectHelper.ifNotEmpty(configurationProperties.getServiceCall().getComponent(), definition::setComponent);
+ ObjectHelper.ifNotEmpty(configurationProperties.getServiceCall().getUri(), definition::setUri);
+ ObjectHelper.ifNotEmpty(configurationProperties.getServiceCall().getServiceDiscovery(), definition::setServiceDiscoveryRef);
+ ObjectHelper.ifNotEmpty(configurationProperties.getServiceCall().getServiceFilter(), definition::setServiceFilterRef);
+ ObjectHelper.ifNotEmpty(configurationProperties.getServiceCall().getServiceChooser(), definition::setServiceChooserRef);
+ ObjectHelper.ifNotEmpty(configurationProperties.getServiceCall().getLoadBalancer(), definition::setLoadBalancerRef);
+
+ String expression = configurationProperties.getServiceCall().getExpression();
+ String expressionLanguage = configurationProperties.getServiceCall().getExpressionLanguage();
+
+ if (ObjectHelper.isNotEmpty(expression) && ObjectHelper.isNotEmpty(expressionLanguage)) {
+ Language language = camelContext.resolveLanguage(expressionLanguage);
+ if (language == null) {
+ throw new IllegalArgumentException("Unable to resolve language: " + expressionLanguage);
+ }
+
+ definition.setExpression(language.createExpression(expression));
+ }
+
+ return definition;
+ }
+
+ // *******************************
+ // Condition
+ // *******************************
+
+ public static class ServiceCallCondition extends GroupCondition {
+ public ServiceCallCondition() {
+ super(
+ "camel.cloud",
+ "camel.cloud.service-call"
+ );
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/cb70f538/components/camel-spring-boot2/src/main/java/org/apache/camel/spring/boot/cloud/CamelCloudServiceChooserAutoConfiguration.java
----------------------------------------------------------------------
diff --git a/components/camel-spring-boot2/src/main/java/org/apache/camel/spring/boot/cloud/CamelCloudServiceChooserAutoConfiguration.java b/components/camel-spring-boot2/src/main/java/org/apache/camel/spring/boot/cloud/CamelCloudServiceChooserAutoConfiguration.java
new file mode 100644
index 0000000..7214eb3
--- /dev/null
+++ b/components/camel-spring-boot2/src/main/java/org/apache/camel/spring/boot/cloud/CamelCloudServiceChooserAutoConfiguration.java
@@ -0,0 +1,43 @@
+/**
+ * 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.cloud;
+
+import org.apache.camel.spring.boot.util.GroupCondition;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
+import org.springframework.boot.context.properties.EnableConfigurationProperties;
+import org.springframework.context.annotation.Conditional;
+import org.springframework.context.annotation.Configuration;
+
+@Configuration
+@ConditionalOnBean(CamelCloudAutoConfiguration.class)
+@EnableConfigurationProperties(CamelCloudConfigurationProperties.class)
+@Conditional(CamelCloudServiceChooserAutoConfiguration.ServiceChooserCondition.class)
+public class CamelCloudServiceChooserAutoConfiguration {
+
+ // *******************************
+ // Condition
+ // *******************************
+
+ public static class ServiceChooserCondition extends GroupCondition {
+ public ServiceChooserCondition() {
+ super(
+ "camel.cloud",
+ "camel.cloud.service-chooser"
+ );
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/cb70f538/components/camel-spring-boot2/src/main/java/org/apache/camel/spring/boot/cloud/CamelCloudServiceDiscovery.java
----------------------------------------------------------------------
diff --git a/components/camel-spring-boot2/src/main/java/org/apache/camel/spring/boot/cloud/CamelCloudServiceDiscovery.java b/components/camel-spring-boot2/src/main/java/org/apache/camel/spring/boot/cloud/CamelCloudServiceDiscovery.java
new file mode 100644
index 0000000..f0400e1
--- /dev/null
+++ b/components/camel-spring-boot2/src/main/java/org/apache/camel/spring/boot/cloud/CamelCloudServiceDiscovery.java
@@ -0,0 +1,47 @@
+/**
+ * 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.cloud;
+
+import java.util.List;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.camel.cloud.ServiceDefinition;
+import org.apache.camel.cloud.ServiceDiscovery;
+import org.apache.camel.impl.cloud.AggregatingServiceDiscovery;
+import org.apache.camel.impl.cloud.CachingServiceDiscovery;
+
+public class CamelCloudServiceDiscovery implements ServiceDiscovery {
+ private ServiceDiscovery delegate;
+
+ public CamelCloudServiceDiscovery(Long timeout, List<ServiceDiscovery> serviceDiscoveryList) {
+ // Created a chained service discovery that collects services from multiple
+ // ServiceDiscovery
+ this.delegate = new AggregatingServiceDiscovery(serviceDiscoveryList);
+
+ // If a timeout is provided, wrap the serviceDiscovery with a caching
+ // strategy so the discovery implementations are not queried for each
+ // discovery request
+ if (timeout != null && timeout > 0) {
+ this.delegate = CachingServiceDiscovery.wrap(this.delegate, timeout, TimeUnit.MILLISECONDS);
+ }
+ }
+
+ @Override
+ public List<ServiceDefinition> getServices(String name) {
+ return delegate.getServices(name);
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/cb70f538/components/camel-spring-boot2/src/main/java/org/apache/camel/spring/boot/cloud/CamelCloudServiceDiscoveryAutoConfiguration.java
----------------------------------------------------------------------
diff --git a/components/camel-spring-boot2/src/main/java/org/apache/camel/spring/boot/cloud/CamelCloudServiceDiscoveryAutoConfiguration.java b/components/camel-spring-boot2/src/main/java/org/apache/camel/spring/boot/cloud/CamelCloudServiceDiscoveryAutoConfiguration.java
new file mode 100644
index 0000000..c374a93
--- /dev/null
+++ b/components/camel-spring-boot2/src/main/java/org/apache/camel/spring/boot/cloud/CamelCloudServiceDiscoveryAutoConfiguration.java
@@ -0,0 +1,128 @@
+/**
+ * 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.cloud;
+
+import java.util.List;
+import java.util.Map;
+import javax.annotation.PostConstruct;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.NoTypeConversionAvailableException;
+import org.apache.camel.cloud.ServiceDiscovery;
+import org.apache.camel.impl.cloud.StaticServiceDiscovery;
+import org.apache.camel.spring.boot.util.GroupCondition;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.BeansException;
+import org.springframework.beans.factory.BeanFactory;
+import org.springframework.beans.factory.BeanFactoryAware;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.config.ConfigurableBeanFactory;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
+import org.springframework.boot.context.properties.EnableConfigurationProperties;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Conditional;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Lazy;
+
+@Configuration
+@ConditionalOnBean(CamelCloudAutoConfiguration.class)
+@EnableConfigurationProperties(CamelCloudConfigurationProperties.class)
+@Conditional(CamelCloudServiceDiscoveryAutoConfiguration.Condition.class)
+public class CamelCloudServiceDiscoveryAutoConfiguration implements BeanFactoryAware {
+ private static final Logger LOGGER = LoggerFactory.getLogger(CamelCloudServiceDiscoveryAutoConfiguration.class);
+
+ private BeanFactory beanFactory;
+
+ @Autowired
+ private CamelContext camelContext;
+ @Autowired
+ private CamelCloudConfigurationProperties configurationProperties;
+
+ @Override
+ public void setBeanFactory(BeanFactory factory) throws BeansException {
+ beanFactory = factory;
+ }
+
+ @Lazy
+ @Bean(name = "static-service-discovery")
+ public ServiceDiscovery staticServiceDiscovery() {
+ return createStaticServiceDiscovery(configurationProperties.getServiceDiscovery());
+ }
+
+ @Lazy
+ @Bean(name = "service-discovery")
+ public CamelCloudServiceDiscovery serviceDiscovery(List<ServiceDiscovery> serviceDiscoveryList) throws NoTypeConversionAvailableException {
+ String cacheTimeout = configurationProperties.getServiceDiscovery().getCacheTimeout();
+ Long timeout = null;
+
+ if (cacheTimeout != null) {
+ timeout = camelContext.getTypeConverter().mandatoryConvertTo(Long.class, timeout);
+ }
+
+ return new CamelCloudServiceDiscovery(timeout, serviceDiscoveryList);
+ }
+
+ @PostConstruct
+ public void addServiceDiscoveryConfigurations() {
+ if (!(beanFactory instanceof ConfigurableBeanFactory)) {
+ LOGGER.warn("BeanFactory is not of type ConfigurableBeanFactory");
+ return;
+ }
+
+ final ConfigurableBeanFactory factory = (ConfigurableBeanFactory) beanFactory;
+
+ configurationProperties.getServiceDiscovery().getConfigurations().entrySet().stream()
+ .forEach(entry -> registerBean(factory, entry.getKey(), entry.getValue()));
+ }
+
+ // *******************************
+ // Condition
+ // *******************************
+
+ public static class Condition extends GroupCondition {
+ public Condition() {
+ super(
+ "camel.cloud",
+ "camel.cloud.service-discovery"
+ );
+ }
+ }
+
+ // *******************************
+ // Helper
+ // *******************************
+
+ private void registerBean(ConfigurableBeanFactory factory, String name, CamelCloudConfigurationProperties.ServiceDiscoveryConfiguration configuration) {
+ factory.registerSingleton(
+ name,
+ createStaticServiceDiscovery(configuration)
+ );
+ }
+
+ private ServiceDiscovery createStaticServiceDiscovery(CamelCloudConfigurationProperties.ServiceDiscoveryConfiguration configuration) {
+ StaticServiceDiscovery staticServiceDiscovery = new StaticServiceDiscovery();
+
+ Map<String, List<String>> services = configuration.getServices();
+ for (Map.Entry<String, List<String>> entry : services.entrySet()) {
+ staticServiceDiscovery.addServers(entry.getKey(), entry.getValue());
+ }
+
+ return staticServiceDiscovery;
+ }
+}