You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by lb...@apache.org on 2017/08/08 11:30:35 UTC

[01/10] camel git commit: CAMEL-11588: SupervisingRouteController - Routes may be started in wrong order

Repository: camel
Updated Branches:
  refs/heads/master d901b59e8 -> 43ca13886


CAMEL-11588: SupervisingRouteController - Routes may be started in wrong order


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/0be3d902
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/0be3d902
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/0be3d902

Branch: refs/heads/master
Commit: 0be3d9025dbbc3095e2553190e6740816bed1fdb
Parents: d901b59
Author: lburgazzoli <lb...@gmail.com>
Authored: Fri Aug 4 16:43:15 2017 +0200
Committer: lburgazzoli <lb...@gmail.com>
Committed: Tue Aug 8 13:29:24 2017 +0200

----------------------------------------------------------------------
 .../camel/impl/SupervisingRouteController.java  | 299 ++++++++++++-------
 1 file changed, 187 insertions(+), 112 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/0be3d902/camel-core/src/main/java/org/apache/camel/impl/SupervisingRouteController.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/impl/SupervisingRouteController.java b/camel-core/src/main/java/org/apache/camel/impl/SupervisingRouteController.java
index 1f92653..aaa6796 100644
--- a/camel-core/src/main/java/org/apache/camel/impl/SupervisingRouteController.java
+++ b/camel-core/src/main/java/org/apache/camel/impl/SupervisingRouteController.java
@@ -17,7 +17,6 @@
 package org.apache.camel.impl;
 
 import java.util.Collection;
-import java.util.Comparator;
 import java.util.EventObject;
 import java.util.HashMap;
 import java.util.List;
@@ -31,20 +30,25 @@ import java.util.concurrent.ConcurrentMap;
 import java.util.concurrent.ScheduledExecutorService;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicInteger;
 import java.util.stream.Collectors;
 
 import org.apache.camel.CamelContext;
 import org.apache.camel.Exchange;
 import org.apache.camel.Experimental;
 import org.apache.camel.Route;
+import org.apache.camel.RuntimeCamelException;
 import org.apache.camel.ServiceStatus;
 import org.apache.camel.StartupListener;
 import org.apache.camel.management.event.CamelContextStartedEvent;
 import org.apache.camel.model.RouteDefinition;
+import org.apache.camel.spi.HasId;
+import org.apache.camel.spi.RouteContext;
 import org.apache.camel.spi.RouteController;
 import org.apache.camel.spi.RoutePolicy;
 import org.apache.camel.spi.RoutePolicyFactory;
 import org.apache.camel.support.EventNotifierSupport;
+import org.apache.camel.util.ObjectHelper;
 import org.apache.camel.util.backoff.BackOff;
 import org.apache.camel.util.backoff.BackOffContext;
 import org.apache.camel.util.backoff.BackOffTimer;
@@ -63,8 +67,8 @@ public class SupervisingRouteController extends DefaultRouteController {
     private static final Logger LOGGER = LoggerFactory.getLogger(SupervisingRouteController.class);
     private final Object lock;
     private final AtomicBoolean contextStarted;
-    private final Set<Route> startedRoutes;
-    private final Set<Route> stoppedRoutes;
+    private final AtomicInteger routeCount;
+    private final Set<RouteHolder> routes;
     private final CamelContextStartupListener listener;
     private final RouteManager routeManager;
     private BackOffTimer timer;
@@ -73,14 +77,10 @@ public class SupervisingRouteController extends DefaultRouteController {
     private Map<String, BackOff> backOffConfigurations;
 
     public SupervisingRouteController() {
-        final Comparator<Route> comparator = Comparator.comparing(
-            route -> Optional.ofNullable(route.getRouteContext().getRoute().getStartupOrder()).orElse(Integer.MIN_VALUE)
-        );
-
         this.lock = new Object();
         this.contextStarted = new AtomicBoolean(false);
-        this.stoppedRoutes = new TreeSet<>(comparator);
-        this.startedRoutes = new TreeSet<>(comparator.reversed());
+        this.routeCount = new AtomicInteger(0);
+        this.routes = new TreeSet<>();
         this.routeManager = new RouteManager();
         this.defaultBackOff = BackOff.builder().build();
         this.backOffConfigurations = new HashMap<>();
@@ -160,96 +160,103 @@ public class SupervisingRouteController extends DefaultRouteController {
 
     @Override
     public void startRoute(String routeId) throws Exception {
-        final CamelContext context = getCamelContext();
-        final Route route = context.getRoute(routeId);
+        final Optional<RouteHolder> route = routes.stream().filter(r -> r.getId().equals(routeId)).findFirst();
 
-        if (route == null) {
-            return;
+        if (!route.isPresent()) {
+            // This route is unknown to this controller, apply default behaviour
+            // from super class.
+            super.startRoute(routeId);
+        } else {
+            doStartRoute(route.get(), true, r -> super.startRoute(routeId));
         }
-
-        doStartRoute(context, route, true, r -> super.startRoute(routeId));
     }
 
     @Override
     public void stopRoute(String routeId) throws Exception {
-        final CamelContext context = getCamelContext();
-        final Route route = context.getRoute(routeId);
+        final Optional<RouteHolder> route = routes.stream().filter(r -> r.getId().equals(routeId)).findFirst();
 
-        if (route == null) {
-            return;
+        if (!route.isPresent()) {
+            // This route is unknown to this controller, apply default behaviour
+            // from super class.
+            super.stopRoute(routeId);
+        } else {
+            doStopRoute(route.get(), true, r -> super.stopRoute(routeId));
         }
-
-        doStopRoute(context, route, true, r -> super.stopRoute(routeId));
     }
 
     @Override
     public void stopRoute(String routeId, long timeout, TimeUnit timeUnit) throws Exception {
-        final CamelContext context = getCamelContext();
-        final Route route = context.getRoute(routeId);
+        final Optional<RouteHolder> route = routes.stream().filter(r -> r.getId().equals(routeId)).findFirst();
 
-        if (route == null) {
-            return;
+        if (!route.isPresent()) {
+            // This route is unknown to this controller, apply default behaviour
+            // from super class.
+            super.stopRoute(routeId, timeout, timeUnit);
+        } else {
+            doStopRoute(route.get(), true, r -> super.stopRoute(r.getId(), timeout, timeUnit));
         }
-
-        doStopRoute(context, route, true, r -> super.stopRoute(r.getId(), timeout, timeUnit));
     }
 
     @Override
     public boolean stopRoute(String routeId, long timeout, TimeUnit timeUnit, boolean abortAfterTimeout) throws Exception {
-        final CamelContext context = getCamelContext();
-        final Route route = context.getRoute(routeId);
-        final AtomicBoolean result = new AtomicBoolean(false);
-
-        if (route == null) {
-            return false;
-        }
+        final Optional<RouteHolder> route = routes.stream().filter(r -> r.getId().equals(routeId)).findFirst();
 
-        doStopRoute(context, route, true, r -> result.set(super.stopRoute(r.getId(), timeout, timeUnit, abortAfterTimeout)));
+        if (!route.isPresent()) {
+            // This route is unknown to this controller, apply default behaviour
+            // from super class.
+            return super.stopRoute(routeId, timeout, timeUnit, abortAfterTimeout);
+        } else {
+            final AtomicBoolean result = new AtomicBoolean(false);
 
-        return result.get();
+            doStopRoute(route.get(), true, r -> result.set(super.stopRoute(r.getId(), timeout, timeUnit, abortAfterTimeout)));
+            return result.get();
+        }
     }
 
     @Override
     public void suspendRoute(String routeId) throws Exception {
-        final CamelContext context = getCamelContext();
-        final Route route = context.getRoute(routeId);
+        final Optional<RouteHolder> route = routes.stream().filter(r -> r.getId().equals(routeId)).findFirst();
 
-        if (route == null) {
-            return;
+        if (!route.isPresent()) {
+            // This route is unknown to this controller, apply default behaviour
+            // from super class.
+            super.suspendRoute(routeId);
+        } else {
+            doStopRoute(route.get(), true, r -> super.suspendRoute(r.getId()));
         }
-
-        doStopRoute(context, route, true, r -> super.suspendRoute(r.getId()));
     }
 
     @Override
     public void suspendRoute(String routeId, long timeout, TimeUnit timeUnit) throws Exception {
-        final CamelContext context = getCamelContext();
-        final Route route = context.getRoute(routeId);
+        final Optional<RouteHolder> route = routes.stream().filter(r -> r.getId().equals(routeId)).findFirst();
 
-        if (route == null) {
-            return;
+        if (!route.isPresent()) {
+            // This route is unknown to this controller, apply default behaviour
+            // from super class.
+            super.suspendRoute(routeId, timeout, timeUnit);
+        } else {
+            doStopRoute(route.get(), true, r -> super.suspendRoute(r.getId(), timeout, timeUnit));
         }
-
-        doStopRoute(context, route, true, r -> super.suspendRoute(r.getId(), timeout, timeUnit));
     }
 
     @Override
     public void resumeRoute(String routeId) throws Exception {
-        final CamelContext context = getCamelContext();
-        final Route route = context.getRoute(routeId);
+        final Optional<RouteHolder> route = routes.stream().filter(r -> r.getId().equals(routeId)).findFirst();
 
-        if (route == null) {
-            return;
+        if (!route.isPresent()) {
+            // This route is unknown to this controller, apply default behaviour
+            // from super class.
+            super.resumeRoute(routeId);
+        } else {
+            doStartRoute(route.get(), true, r -> super.startRoute(routeId));
         }
-
-        doStartRoute(context, route, true, r -> super.startRoute(routeId));
     }
 
     // *********************************
     // Helpers
     // *********************************
 
-    private void doStopRoute(CamelContext context, Route route,  boolean checker, ThrowingConsumer<Route, Exception> consumer) throws Exception {
+    private void doStopRoute(RouteHolder route,  boolean checker, ThrowingConsumer<RouteHolder, Exception> consumer) throws Exception {
         synchronized (lock) {
             if (checker) {
                 // remove them from checked routes so they don't get started by the
@@ -258,7 +265,7 @@ public class SupervisingRouteController extends DefaultRouteController {
                 routeManager.release(route);
             }
 
-            ServiceStatus status = context.getRouteStatus(route.getId());
+            ServiceStatus status = route.getStatus();
             if (!status.isStoppable()) {
                 LOGGER.debug("Route {} status is {}, skipping", route.getId(), status);
                 return;
@@ -266,38 +273,28 @@ public class SupervisingRouteController extends DefaultRouteController {
 
             consumer.accept(route);
 
-            startedRoutes.remove(route);
-            stoppedRoutes.add(route);
-
             // Mark the route as un-managed
-            route.getRouteContext().setRouteController(null);
+            route.getContext().setRouteController(null);
         }
     }
 
-    private void doStartRoute(CamelContext context, Route route, boolean checker, ThrowingConsumer<Route, Exception> consumer) throws Exception {
+    private void doStartRoute(RouteHolder route, boolean checker, ThrowingConsumer<RouteHolder, Exception> consumer) throws Exception {
         synchronized (lock) {
-            ServiceStatus status = context.getRouteStatus(route.getId());
+            ServiceStatus status = route.getStatus();
             if (!status.isStartable()) {
                 LOGGER.debug("Route {} status is {}, skipping", route.getId(), status);
                 return;
             }
 
             try {
-                // remove the route from any queue
-                stoppedRoutes.remove(route);
-                startedRoutes.remove(route);
-
                 if (checker) {
                     routeManager.release(route);
                 }
 
                 // Mark the route as managed
-                route.getRouteContext().setRouteController(this);
+                route.getContext().setRouteController(this);
 
                 consumer.accept(route);
-
-                // route started successfully
-                startedRoutes.add(route);
             } catch (Exception e) {
 
                 if (checker) {
@@ -316,13 +313,16 @@ public class SupervisingRouteController extends DefaultRouteController {
             return;
         }
 
-        List<String> routes;
+        final List<String> routeList;
 
         synchronized (lock) {
-            routes = stoppedRoutes.stream().map(Route::getId).collect(Collectors.toList());
+            routeList = routes.stream()
+                .filter(r -> r.getStatus() == ServiceStatus.Stopped)
+                .map(RouteHolder::getId)
+                .collect(Collectors.toList());
         }
 
-        for (String route: routes) {
+        for (String route: routeList) {
             try {
                 startRoute(route);
             } catch (Exception e) {
@@ -332,13 +332,20 @@ public class SupervisingRouteController extends DefaultRouteController {
     }
 
     private synchronized void stopRoutes() {
-        List<String> routes;
+        if (!isRunAllowed()) {
+            return;
+        }
+
+        final List<String> routeList;
 
         synchronized (lock) {
-            routes = startedRoutes.stream().map(Route::getId).collect(Collectors.toList());
+            routeList = routes.stream()
+                .filter(r -> r.getStatus() == ServiceStatus.Started)
+                .map(RouteHolder::getId)
+                .collect(Collectors.toList());
         }
 
-        for (String route: routes) {
+        for (String route: routeList) {
             try {
                 stopRoute(route);
             } catch (Exception e) {
@@ -353,17 +360,15 @@ public class SupervisingRouteController extends DefaultRouteController {
 
     private class RouteManager {
         private final Logger logger;
-        private final ConcurrentMap<Route, CompletableFuture<BackOffContext>> routes;
+        private final ConcurrentMap<RouteHolder, CompletableFuture<BackOffContext>> routes;
 
         RouteManager() {
             this.logger = LoggerFactory.getLogger(RouteManager.class);
             this.routes = new ConcurrentHashMap<>();
         }
 
-        void start(Route route) {
-            route.getRouteContext().setRouteController(SupervisingRouteController.this);
-            
-            final CamelContext camelContext = getCamelContext();
+        void start(RouteHolder route) {
+            route.getContext().setRouteController(SupervisingRouteController.this);
 
             routes.computeIfAbsent(
                 route,
@@ -378,7 +383,7 @@ public class SupervisingRouteController extends DefaultRouteController {
                         try {
                             logger.info("Try to restart route: {}", r.getId());
 
-                            doStartRoute(camelContext, r, false, rx -> SupervisingRouteController.super.startRoute(rx.getId()));
+                            doStartRoute(r, false, rx -> SupervisingRouteController.super.startRoute(rx.getId()));
                             return false;
                         } catch (Exception e) {
                             return true;
@@ -396,17 +401,12 @@ public class SupervisingRouteController extends DefaultRouteController {
                             }
 
                             synchronized (lock) {
-                                ServiceStatus status = camelContext.getRouteStatus(route.getId());
+                                final ServiceStatus status = route.getStatus();
 
                                 if (status.isStopped() || status.isStopping()) {
                                     LOGGER.info("Route {} has status {}, stop supervising it", route.getId(), status);
 
-                                    r.getRouteContext().setRouteController(null);
-                                    stoppedRoutes.add(r);
-                                } else if (status.isStarted() || status.isStarting()) {
-                                    synchronized (lock) {
-                                        startedRoutes.add(r);
-                                    }
+                                    r.getContext().setRouteController(null);
                                 }
                             }
                         }
@@ -419,7 +419,7 @@ public class SupervisingRouteController extends DefaultRouteController {
             );
         }
 
-        boolean release(Route route) {
+        boolean release(RouteHolder route) {
             CompletableFuture<BackOffContext> future = routes.remove(route);
             if (future != null) {
                 future.cancel(true);
@@ -433,18 +433,87 @@ public class SupervisingRouteController extends DefaultRouteController {
             routes.clear();
         }
 
-        boolean isSupervising(Route route) {
+        boolean isSupervising(RouteHolder route) {
             return routes.containsKey(route);
         }
 
-        Collection<Route> routes() {
+        Collection<RouteHolder> routes() {
             return routes.keySet();
         }
     }
 
-    private boolean isSupervising(Route route) {
-        synchronized (lock) {
-            return stoppedRoutes.contains(route) || startedRoutes.contains(route) || routeManager.isSupervising(route);
+    // *********************************
+    //
+    // *********************************
+
+    private class RouteHolder implements HasId, Comparable<RouteHolder> {
+        private final int order;
+        private final Route route;
+
+        RouteHolder(Route route, int order) {
+            this.route = route;
+            this.order = order;
+        }
+
+        @Override
+        public String getId() {
+            return this.route.getId();
+        }
+
+        public Route get() {
+            return this.route;
+        }
+
+        public RouteContext getContext() {
+            return this.route.getRouteContext();
+        }
+
+        public RouteDefinition getDefinition() {
+            return this.route.getRouteContext().getRoute();
+        }
+
+        public ServiceStatus getStatus() {
+            return getContext().getCamelContext().getRouteStatus(getId());
+        }
+
+        public int getInitializationOrder() {
+            return order;
+        }
+
+        public int getStartupOrder() {
+            Integer order = getDefinition().getStartupOrder();
+            if (order == null) {
+                order = Integer.MAX_VALUE;
+            }
+
+            return order;
+        }
+
+        @Override
+        public int compareTo(RouteHolder o) {
+            int answer = Integer.compare(getStartupOrder(), o.getStartupOrder());
+            if (answer == 0) {
+                answer = Integer.compare(getInitializationOrder(), o.getInitializationOrder());
+            }
+
+            return answer;
+        }
+
+        @Override
+        public boolean equals(Object o) {
+            if (this == o) {
+                return true;
+            }
+            if (o == null || getClass() != o.getClass()) {
+                return false;
+            }
+
+            return this.route.equals(((RouteHolder)o).route);
+        }
+
+        @Override
+        public int hashCode() {
+            return route.hashCode();
         }
     }
 
@@ -464,29 +533,35 @@ public class SupervisingRouteController extends DefaultRouteController {
     private class ManagedRoutePolicy implements RoutePolicy {
         @Override
         public void onInit(Route route) {
-            route.getRouteContext().setRouteController(SupervisingRouteController.this);
-            route.getRouteContext().getRoute().setAutoStartup("false");
-
-            if (contextStarted.get()) {
-                LOGGER.debug("Context is started: add route {} to startable routes", route.getId());
-                try {
-                    SupervisingRouteController.this.doStartRoute(
-                        getCamelContext(),
-                        route,
-                        true,
-                        r -> SupervisingRouteController.super.startRoute(r.getId())
-                    );
-                } catch (Exception e) {
-                    e.printStackTrace();
+            RouteHolder holder = new RouteHolder(route, routeCount.incrementAndGet());
+            if (routes.add(holder)) {
+                holder.getContext().setRouteController(SupervisingRouteController.this);
+                holder.getDefinition().setAutoStartup("false");
+
+                if (contextStarted.get()) {
+                    LOGGER.debug("Context is started: attempt to start route {}", route.getId());
+                    try {
+                        SupervisingRouteController.this.doStartRoute(
+                            holder,
+                            true,
+                            r -> SupervisingRouteController.super.startRoute(r.getId())
+                        );
+                    } catch (Exception e) {
+                        throw new RuntimeCamelException(e);
+                    }
+                } else {
+                    LOGGER.debug("Context is not started: add route {} to stopped routes", holder.getId());
                 }
-            } else {
-                LOGGER.debug("Context is not started: add route {} to stopped routes", route.getId());
-                stoppedRoutes.add(route);
             }
         }
 
         @Override
         public void onRemove(Route route) {
+            synchronized (lock) {
+                routes.removeIf(
+                    r -> ObjectHelper.equal(r.get(), route) || ObjectHelper.equal(r.getId(), route.getId())
+                );
+            }
         }
 
         @Override


[10/10] camel git commit: CAMEL-11580: Add JMX api RouteController and SupervisingRouteController

Posted by lb...@apache.org.
CAMEL-11580: Add JMX api RouteController and SupervisingRouteController


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/43ca1388
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/43ca1388
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/43ca1388

Branch: refs/heads/master
Commit: 43ca138867997d4997dadd30db080aef7bc9ef2d
Parents: 2b832e9
Author: lburgazzoli <lb...@gmail.com>
Authored: Mon Aug 7 17:08:44 2017 +0200
Committer: lburgazzoli <lb...@gmail.com>
Committed: Tue Aug 8 13:29:29 2017 +0200

----------------------------------------------------------------------
 .../mbean/ManagedRouteControllerMBean.java      | 27 +++++++
 .../DefaultManagementLifecycleStrategy.java     | 22 ++++++
 .../DefaultManagementNamingStrategy.java        | 18 +++++
 .../DefaultManagementObjectStrategy.java        |  7 ++
 .../management/ManagedManagementStrategy.java   |  4 +
 .../mbean/ManagedRouteController.java           | 57 ++++++++++++++
 .../camel/spi/ManagementNamingStrategy.java     |  2 +
 .../camel/spi/ManagementObjectStrategy.java     |  2 +
 .../endpoint/CamelRouteControllerEndpoint.java  | 60 +++++++++++++++
 ...outeControllerEndpointAutoConfiguration.java | 49 ++++++++++++
 .../CamelRouteControllerMvcEndpoint.java        | 79 ++++++++++++++++++++
 .../main/resources/META-INF/spring.factories    |  1 +
 12 files changed, 328 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/43ca1388/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedRouteControllerMBean.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedRouteControllerMBean.java b/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedRouteControllerMBean.java
new file mode 100644
index 0000000..4422ed8
--- /dev/null
+++ b/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedRouteControllerMBean.java
@@ -0,0 +1,27 @@
+/**
+ * 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.api.management.mbean;
+
+import java.util.Collection;
+
+import org.apache.camel.api.management.ManagedAttribute;
+
+public interface ManagedRouteControllerMBean {
+
+    @ManagedAttribute(description = "Controlled Routes")
+    Collection<String> getControlledRoutes();
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/camel/blob/43ca1388/camel-core/src/main/java/org/apache/camel/management/DefaultManagementLifecycleStrategy.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/management/DefaultManagementLifecycleStrategy.java b/camel-core/src/main/java/org/apache/camel/management/DefaultManagementLifecycleStrategy.java
index 9a70390..3cf6f09 100644
--- a/camel-core/src/main/java/org/apache/camel/management/DefaultManagementLifecycleStrategy.java
+++ b/camel-core/src/main/java/org/apache/camel/management/DefaultManagementLifecycleStrategy.java
@@ -219,6 +219,17 @@ public class DefaultManagementLifecycleStrategy extends ServiceSupport implement
 
         // register any pre registered now that we are initialized
         enlistPreRegisteredServices();
+
+        try {
+            Object me = getManagementObjectStrategy().getManagedObjectForRouteController(camelContext);
+            if (me == null) {
+                // endpoint should not be managed
+                return;
+            }
+            manageObject(me);
+        } catch (Exception e) {
+            LOG.warn("Could not register RouteController MBean. This exception will be ignored.", e);
+        }
     }
 
     private String findFreeName(Object mc, ManagementNameStrategy strategy, String name) throws MalformedObjectNameException {
@@ -276,6 +287,17 @@ public class DefaultManagementLifecycleStrategy extends ServiceSupport implement
         if (!initialized) {
             return;
         }
+
+        try {
+            Object mc = getManagementObjectStrategy().getManagedObjectForRouteController(context);
+            // the context could have been removed already
+            if (getManagementStrategy().isManaged(mc, null)) {
+                unmanageObject(mc);
+            }
+        } catch (Exception e) {
+            LOG.warn("Could not unregister RouteController MBean", e);
+        }
+
         try {
             Object mc = getManagementObjectStrategy().getManagedObjectForCamelContext(context);
             // the context could have been removed already

http://git-wip-us.apache.org/repos/asf/camel/blob/43ca1388/camel-core/src/main/java/org/apache/camel/management/DefaultManagementNamingStrategy.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/management/DefaultManagementNamingStrategy.java b/camel-core/src/main/java/org/apache/camel/management/DefaultManagementNamingStrategy.java
index 56b85c8..341b9e9 100644
--- a/camel-core/src/main/java/org/apache/camel/management/DefaultManagementNamingStrategy.java
+++ b/camel-core/src/main/java/org/apache/camel/management/DefaultManagementNamingStrategy.java
@@ -52,6 +52,7 @@ public class DefaultManagementNamingStrategy implements ManagementNamingStrategy
     public static final String KEY_TYPE = "type";
     public static final String KEY_CONTEXT = "context";
     public static final String TYPE_CONTEXT = "context";
+    public static final String TYPE_ROUTE_CONTROLLER= "routecontroller";
     public static final String TYPE_ENDPOINT = "endpoints";
     public static final String TYPE_DATAFORMAT = "dataformats";
     public static final String TYPE_PROCESSOR = "processors";
@@ -112,6 +113,23 @@ public class DefaultManagementNamingStrategy implements ManagementNamingStrategy
         return getObjectNameForCamelContext(managementName, name);
     }
 
+    @Override
+    public ObjectName getObjectNameForRouteController(CamelContext context) throws MalformedObjectNameException {
+        // prefer to use the given management name if previously assigned
+        String managementName = context.getManagementName();
+        if (managementName == null) {
+            managementName = context.getManagementNameStrategy().getName();
+        }
+
+        StringBuilder buffer = new StringBuilder();
+        buffer.append(domainName).append(":");
+        buffer.append(KEY_CONTEXT + "=").append(getContextId(managementName)).append(",");
+        buffer.append(KEY_TYPE + "=" + TYPE_ROUTE_CONTROLLER + ",");
+        buffer.append(KEY_NAME + "=").append(ObjectName.quote(context.getName()));
+
+        return createObjectName(buffer);
+    }
+
     public ObjectName getObjectNameForEndpoint(Endpoint endpoint) throws MalformedObjectNameException {
         StringBuilder buffer = new StringBuilder();
         buffer.append(domainName).append(":");

http://git-wip-us.apache.org/repos/asf/camel/blob/43ca1388/camel-core/src/main/java/org/apache/camel/management/DefaultManagementObjectStrategy.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/management/DefaultManagementObjectStrategy.java b/camel-core/src/main/java/org/apache/camel/management/DefaultManagementObjectStrategy.java
index c53cffb..8e785f2 100644
--- a/camel-core/src/main/java/org/apache/camel/management/DefaultManagementObjectStrategy.java
+++ b/camel-core/src/main/java/org/apache/camel/management/DefaultManagementObjectStrategy.java
@@ -70,6 +70,7 @@ import org.apache.camel.management.mbean.ManagedResequencer;
 import org.apache.camel.management.mbean.ManagedRollback;
 import org.apache.camel.management.mbean.ManagedRoundRobinLoadBalancer;
 import org.apache.camel.management.mbean.ManagedRoute;
+import org.apache.camel.management.mbean.ManagedRouteController;
 import org.apache.camel.management.mbean.ManagedRoutingSlip;
 import org.apache.camel.management.mbean.ManagedSamplingThrottler;
 import org.apache.camel.management.mbean.ManagedScheduledPollConsumer;
@@ -220,6 +221,12 @@ public class DefaultManagementObjectStrategy implements ManagementObjectStrategy
         return me;
     }
 
+    public Object getManagedObjectForRouteController(CamelContext context) {
+        ManagedRouteController mrc = new ManagedRouteController((ModelCamelContext)context);
+        mrc.init(context.getManagementStrategy());
+        return mrc;
+    }
+
     public Object getManagedObjectForRoute(CamelContext context, Route route) {
         ManagedRoute mr;
         if (route.supportsSuspension()) {

http://git-wip-us.apache.org/repos/asf/camel/blob/43ca1388/camel-core/src/main/java/org/apache/camel/management/ManagedManagementStrategy.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/management/ManagedManagementStrategy.java b/camel-core/src/main/java/org/apache/camel/management/ManagedManagementStrategy.java
index 58a6982..5754a50 100644
--- a/camel-core/src/main/java/org/apache/camel/management/ManagedManagementStrategy.java
+++ b/camel-core/src/main/java/org/apache/camel/management/ManagedManagementStrategy.java
@@ -32,6 +32,7 @@ import org.apache.camel.management.mbean.ManagedEventNotifier;
 import org.apache.camel.management.mbean.ManagedProcessor;
 import org.apache.camel.management.mbean.ManagedProducer;
 import org.apache.camel.management.mbean.ManagedRoute;
+import org.apache.camel.management.mbean.ManagedRouteController;
 import org.apache.camel.management.mbean.ManagedService;
 import org.apache.camel.management.mbean.ManagedThreadPool;
 import org.apache.camel.management.mbean.ManagedTracer;
@@ -89,6 +90,9 @@ public class ManagedManagementStrategy extends DefaultManagementStrategy {
         if (managedObject instanceof ManagedCamelContext) {
             ManagedCamelContext mcc = (ManagedCamelContext) managedObject;
             objectName = getManagementNamingStrategy().getObjectNameForCamelContext(mcc.getContext());
+        } else if (managedObject instanceof ManagedRouteController) {
+            ManagedRouteController mrc = (ManagedRouteController) managedObject;
+            objectName = getManagementNamingStrategy().getObjectNameForRouteController(mrc.getContext());
         } else if (managedObject instanceof ManagedComponent) {
             ManagedComponent mc = (ManagedComponent) managedObject;
             objectName = getManagementNamingStrategy().getObjectNameForComponent(mc.getComponent(), mc.getComponentName());

http://git-wip-us.apache.org/repos/asf/camel/blob/43ca1388/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedRouteController.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedRouteController.java b/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedRouteController.java
new file mode 100644
index 0000000..936f54c
--- /dev/null
+++ b/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedRouteController.java
@@ -0,0 +1,57 @@
+/**
+ * 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.management.mbean;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.stream.Collectors;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Route;
+import org.apache.camel.api.management.mbean.ManagedRouteControllerMBean;
+import org.apache.camel.model.ModelCamelContext;
+import org.apache.camel.spi.ManagementStrategy;
+import org.apache.camel.spi.RouteController;
+
+public class ManagedRouteController implements ManagedRouteControllerMBean {
+    private final ModelCamelContext context;
+
+    public ManagedRouteController(ModelCamelContext context) {
+        this.context = context;
+    }
+
+    public void init(ManagementStrategy strategy) {
+        // do nothing
+    }
+
+    public CamelContext getContext() {
+        return context;
+    }
+
+    @Override
+    public Collection<String> getControlledRoutes() {
+        RouteController controller = context.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/43ca1388/camel-core/src/main/java/org/apache/camel/spi/ManagementNamingStrategy.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/spi/ManagementNamingStrategy.java b/camel-core/src/main/java/org/apache/camel/spi/ManagementNamingStrategy.java
index f363567..72bb00a 100644
--- a/camel-core/src/main/java/org/apache/camel/spi/ManagementNamingStrategy.java
+++ b/camel-core/src/main/java/org/apache/camel/spi/ManagementNamingStrategy.java
@@ -44,6 +44,8 @@ public interface ManagementNamingStrategy {
 
     ObjectName getObjectNameForCamelContext(CamelContext context) throws MalformedObjectNameException;
 
+    ObjectName getObjectNameForRouteController(CamelContext context) throws MalformedObjectNameException;
+
     ObjectName getObjectNameForComponent(Component component, String name) throws MalformedObjectNameException;
 
     ObjectName getObjectNameForEndpoint(Endpoint endpoint) throws MalformedObjectNameException;

http://git-wip-us.apache.org/repos/asf/camel/blob/43ca1388/camel-core/src/main/java/org/apache/camel/spi/ManagementObjectStrategy.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/spi/ManagementObjectStrategy.java b/camel-core/src/main/java/org/apache/camel/spi/ManagementObjectStrategy.java
index b6acc7f..a11b2b1 100644
--- a/camel-core/src/main/java/org/apache/camel/spi/ManagementObjectStrategy.java
+++ b/camel-core/src/main/java/org/apache/camel/spi/ManagementObjectStrategy.java
@@ -45,6 +45,8 @@ public interface ManagementObjectStrategy {
     Object getManagedObjectForErrorHandler(CamelContext context, RouteContext routeContext,
                                            Processor errorHandler, ErrorHandlerFactory errorHandlerBuilder);
 
+    Object getManagedObjectForRouteController(CamelContext context);
+
     Object getManagedObjectForRoute(CamelContext context, Route route);
 
     Object getManagedObjectForConsumer(CamelContext context, Consumer consumer);

http://git-wip-us.apache.org/repos/asf/camel/blob/43ca1388/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/actuate/endpoint/CamelRouteControllerEndpoint.java
----------------------------------------------------------------------
diff --git a/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/actuate/endpoint/CamelRouteControllerEndpoint.java b/components/camel-spring-boot/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-boot/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/43ca1388/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/actuate/endpoint/CamelRouteControllerEndpointAutoConfiguration.java
----------------------------------------------------------------------
diff --git a/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/actuate/endpoint/CamelRouteControllerEndpointAutoConfiguration.java b/components/camel-spring-boot/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-boot/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/43ca1388/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/actuate/endpoint/CamelRouteControllerMvcEndpoint.java
----------------------------------------------------------------------
diff --git a/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/actuate/endpoint/CamelRouteControllerMvcEndpoint.java b/components/camel-spring-boot/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-boot/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/43ca1388/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 8550060..ac8c58e 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
@@ -19,6 +19,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.endpoint.CamelRouteControllerEndpointAutoConfiguration,\
 org.apache.camel.spring.boot.actuate.health.CamelHealthAutoConfiguration,\
 org.apache.camel.spring.boot.cloud.CamelCloudAutoConfiguration,\
 org.apache.camel.spring.boot.cloud.CamelCloudServiceCallConfigurationAutoConfiguration,\


[02/10] camel git commit: CAMEL-11584: Add javadoc to spring boot auto configuration of camel.supervising.controller

Posted by lb...@apache.org.
CAMEL-11584: Add javadoc to spring boot auto configuration of camel.supervising.controller


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/29a3b28b
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/29a3b28b
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/29a3b28b

Branch: refs/heads/master
Commit: 29a3b28b0c7b4a3caeb78c14d75d5f0393aa191b
Parents: b354cba
Author: lburgazzoli <lb...@gmail.com>
Authored: Mon Aug 7 08:15:10 2017 +0200
Committer: lburgazzoli <lb...@gmail.com>
Committed: Tue Aug 8 13:29:27 2017 +0200

----------------------------------------------------------------------
 ...SupervisingRouteControllerConfiguration.java | 42 ++++++++++++++++++++
 1 file changed, 42 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/29a3b28b/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
index 01c2d0e..32ef447 100644
--- 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
@@ -23,8 +23,19 @@ 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;
+
+    /**
+     * The default back-off configuration, back-off configuration for routes inherits from this default.
+     */
     private BackOffConfiguration backOff = new BackOffConfiguration();
+
+    /**
+     * Routes configuration.
+     */
     private Map<String, RouteConfiguration> routes = new HashMap<>();
 
     public boolean isEnabled() {
@@ -48,6 +59,9 @@ public class SupervisingRouteControllerConfiguration {
     // *****************************************
 
     public static class RouteConfiguration {
+        /**
+         * The back-off configuration from this route, inherits from default back-off
+         */
         private BackOffConfiguration backOff;
 
         public BackOffConfiguration getBackOff() {
@@ -60,10 +74,38 @@ public class SupervisingRouteControllerConfiguration {
     }
 
     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;
+
+        /**
+         * Teh 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() {


[05/10] camel git commit: CAMEL-11587: SupervisingRouteController : add option for initial delay

Posted by lb...@apache.org.
CAMEL-11587: SupervisingRouteController : add option for initial delay


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/ef5aa1f5
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/ef5aa1f5
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/ef5aa1f5

Branch: refs/heads/master
Commit: ef5aa1f561a6ad4fcbf7d8b95d6ef3c4c0b39e5a
Parents: b3ebc7b
Author: lburgazzoli <lb...@gmail.com>
Authored: Mon Aug 7 11:20:01 2017 +0200
Committer: lburgazzoli <lb...@gmail.com>
Committed: Tue Aug 8 13:29:28 2017 +0200

----------------------------------------------------------------------
 .../camel/impl/SupervisingRouteController.java  | 83 +++++++++++++++++---
 ...rvisingRouteControllerAutoConfiguration.java |  4 +
 ...SupervisingRouteControllerConfiguration.java | 15 ++++
 .../src/main/resources/application.properties   |  1 +
 4 files changed, 94 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/ef5aa1f5/camel-core/src/main/java/org/apache/camel/impl/SupervisingRouteController.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/impl/SupervisingRouteController.java b/camel-core/src/main/java/org/apache/camel/impl/SupervisingRouteController.java
index 01396dc..8e5167e 100644
--- a/camel-core/src/main/java/org/apache/camel/impl/SupervisingRouteController.java
+++ b/camel-core/src/main/java/org/apache/camel/impl/SupervisingRouteController.java
@@ -16,6 +16,7 @@
  */
 package org.apache.camel.impl;
 
+import java.time.Duration;
 import java.util.EventObject;
 import java.util.HashMap;
 import java.util.List;
@@ -74,6 +75,7 @@ public class SupervisingRouteController extends DefaultRouteController {
     private ScheduledExecutorService executorService;
     private BackOff defaultBackOff;
     private Map<String, BackOff> backOffConfigurations;
+    private Duration initialDelay;
 
     public SupervisingRouteController() {
         this.lock = new Object();
@@ -83,6 +85,7 @@ public class SupervisingRouteController extends DefaultRouteController {
         this.routeManager = new RouteManager();
         this.defaultBackOff = BackOff.builder().build();
         this.backOffConfigurations = new HashMap<>();
+        this.initialDelay = Duration.ofMillis(0);
 
         try {
             this.listener = new CamelContextStartupListener();
@@ -100,6 +103,9 @@ public class SupervisingRouteController extends DefaultRouteController {
         return defaultBackOff;
     }
 
+    /**
+     * Sets the default back-off.
+     */
     public void setDefaultBackOff(BackOff defaultBackOff) {
         this.defaultBackOff = defaultBackOff;
     }
@@ -108,6 +114,9 @@ public class SupervisingRouteController extends DefaultRouteController {
         return backOffConfigurations;
     }
 
+    /**
+     * Set the back-off for the given IDs.
+     */
     public void setBackOffConfigurations(Map<String, BackOff> backOffConfigurations) {
         this.backOffConfigurations = backOffConfigurations;
     }
@@ -116,10 +125,47 @@ public class SupervisingRouteController extends DefaultRouteController {
         return backOffConfigurations.getOrDefault(id, defaultBackOff);
     }
 
+    /**
+     * Sets the back-off to be applied to the given <code>id</code>.
+     */
     public void setBackOff(String id, BackOff backOff) {
         backOffConfigurations.put(id, backOff);
     }
 
+    public Duration getInitialDelay() {
+        return initialDelay;
+    }
+
+    /**
+     * 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.
+     *
+     * @param initialDelay the initial delay.
+     */
+    public void setInitialDelay(Duration initialDelay) {
+        this.initialDelay = initialDelay;
+    }
+
+    /**
+     * #see {@link this#setInitialDelay(Duration)}
+     *
+     * @param initialDelay the initial delay amount.
+     * @param initialDelay the initial delay time unit.
+     */
+    public void setInitialDelay(long initialDelay, TimeUnit initialDelayUnit) {
+        this.initialDelay = Duration.ofMillis(initialDelayUnit.toMillis(initialDelay));
+    }
+
+    /**
+     * #see {@link this#setInitialDelay(Duration)}
+     *
+     * @param initialDelay the initial delay in milliseconds.
+     */
+    public void setInitialDelay(long initialDelay) {
+        this.initialDelay = Duration.ofMillis(initialDelay);
+    }
+
     // *********************************
     // Lifecycle
     // *********************************
@@ -535,6 +581,19 @@ public class SupervisingRouteController extends DefaultRouteController {
     }
 
     private class ManagedRoutePolicy implements RoutePolicy {
+
+        private void startRoute(RouteHolder holder) {
+            try {
+                SupervisingRouteController.this.doStartRoute(
+                    holder,
+                    true,
+                    r -> SupervisingRouteController.super.startRoute(r.getId())
+                );
+            } catch (Exception e) {
+                throw new RuntimeCamelException(e);
+            }
+        }
+
         @Override
         public void onInit(Route route) {
             if ("false".equals(route.getRouteContext().getRoute().getAutoStartup())) {
@@ -549,14 +608,13 @@ public class SupervisingRouteController extends DefaultRouteController {
 
                 if (contextStarted.get()) {
                     LOGGER.info("Context is already started: attempt to start route {}", route.getId());
-                    try {
-                        SupervisingRouteController.this.doStartRoute(
-                            holder,
-                            true,
-                            r -> SupervisingRouteController.super.startRoute(r.getId())
-                        );
-                    } catch (Exception e) {
-                        throw new RuntimeCamelException(e);
+
+                    // Eventually delay the startup of the route a later time
+                    if (initialDelay.toMillis() > 0) {
+                        LOGGER.debug("Route {} will be started in {}", holder.getId(), initialDelay);
+                        executorService.schedule(() -> startRoute(holder), initialDelay.toMillis(), TimeUnit.MILLISECONDS);
+                    } else {
+                        startRoute(holder);
                     }
                 } else {
                     LOGGER.info("Context is not yet started: defer route {} start", holder.getId());
@@ -633,7 +691,14 @@ public class SupervisingRouteController extends DefaultRouteController {
             // so start/stop of managed routes do not clash with CamelContext
             // startup
             if (contextStarted.compareAndSet(false, true)) {
-                startRoutes();
+
+                // Eventually delay the startup of the routes a later time
+                if (initialDelay.toMillis() > 0) {
+                    LOGGER.debug("Routes will be started in {}", initialDelay);
+                    executorService.schedule(SupervisingRouteController.this::startRoutes, initialDelay.toMillis(), TimeUnit.MILLISECONDS);
+                } else {
+                    startRoutes();
+                }
             }
         }
     }

http://git-wip-us.apache.org/repos/asf/camel/blob/ef5aa1f5/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
index abb747d..9ff36bb 100644
--- 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
@@ -49,6 +49,10 @@ public class SupervisingRouteControllerAutoConfiguration {
     public RouteController routeController() {
         SupervisingRouteController controller = new SupervisingRouteController();
 
+        // Initial delay
+        Optional.ofNullable(configuration.getInitialDelay()).map(TimePatternConverter::toMilliSeconds).ifPresent(controller::setInitialDelay);
+
+        // Back off
         controller.setDefaultBackOff(configureBackOff(Optional.empty(), configuration.getDefaultBackOff()));
 
         for (Map.Entry<String, RouteConfiguration> entry: configuration.getRoutes().entrySet()) {

http://git-wip-us.apache.org/repos/asf/camel/blob/ef5aa1f5/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
index fb667b3..4ab2290 100644
--- 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
@@ -29,6 +29,13 @@ public class SupervisingRouteControllerConfiguration {
     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();
@@ -46,6 +53,14 @@ public class SupervisingRouteControllerConfiguration {
         this.enabled = enabled;
     }
 
+    public String getInitialDelay() {
+        return initialDelay;
+    }
+
+    public void setInitialDelay(String initialDelay) {
+        this.initialDelay = initialDelay;
+    }
+
     public BackOffConfiguration getDefaultBackOff() {
         return defaultBackOff;
     }

http://git-wip-us.apache.org/repos/asf/camel/blob/ef5aa1f5/examples/camel-example-spring-boot-routecontroller/src/main/resources/application.properties
----------------------------------------------------------------------
diff --git a/examples/camel-example-spring-boot-routecontroller/src/main/resources/application.properties b/examples/camel-example-spring-boot-routecontroller/src/main/resources/application.properties
index 9cd0c34..10efe1c 100644
--- a/examples/camel-example-spring-boot-routecontroller/src/main/resources/application.properties
+++ b/examples/camel-example-spring-boot-routecontroller/src/main/resources/application.properties
@@ -37,6 +37,7 @@ management.security.enabled = false
 camel.springboot.name = SampleSupervisingRouteController
 
 camel.supervising.controller.enabled = true
+camel.supervising.controller.initial-delay = 5s
 camel.supervising.controller.default-back-off.delay = 5s
 camel.supervising.controller.default-back-off.max-attempts = 10
 camel.supervising.controller.routes.undertow.back-off.delay = 10s


[04/10] camel git commit: CAMEL-11583: SupervisingRouteController should honor if a route was explicit set to autoStartup=false

Posted by lb...@apache.org.
CAMEL-11583: SupervisingRouteController should honor if a route was explicit set to autoStartup=false


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/6893a37f
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/6893a37f
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/6893a37f

Branch: refs/heads/master
Commit: 6893a37f28c82dbc70a05b7cebc720fa40c641cf
Parents: 0be3d90
Author: lburgazzoli <lb...@gmail.com>
Authored: Fri Aug 4 17:53:07 2017 +0200
Committer: lburgazzoli <lb...@gmail.com>
Committed: Tue Aug 8 13:29:27 2017 +0200

----------------------------------------------------------------------
 .../apache/camel/impl/DefaultCamelContext.java  | 17 +++++++++++++++-
 .../camel/impl/DefaultRouteController.java      |  5 +++++
 .../camel/impl/SupervisingRouteController.java  | 21 +++++++++++---------
 .../org/apache/camel/spi/RouteController.java   |  9 +++++++++
 .../java/sample/camel/ApplicationRoutes.java    |  5 +++++
 5 files changed, 47 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/6893a37f/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java b/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
index b46b6c2..1856ebd 100644
--- a/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
+++ b/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
@@ -3170,7 +3170,22 @@ public class DefaultCamelContext extends ServiceSupport implements ModelCamelCon
                         started++;
                     }
                 }
-                log.info("Total " + getRoutes().size() + " routes, of which " + started + " are started.");
+
+                final List<Route> controlledRoutes = getRouteController().getControlledRoutes();
+
+                if (controlledRoutes.isEmpty()) {
+                    log.info("Total {} routes, of which {} are started",
+                        getRoutes().size(),
+                        started);
+                } else {
+                    log.info("Total {} routes, of which {} are started and {} are managed by the route controller ({})",
+                        getRoutes().size(),
+                        started,
+                        controlledRoutes.size(),
+                        getRouteController().getClass().getName()
+                    );
+                }
+
                 log.info("Apache Camel " + getVersion() + " (CamelContext: " + getName() + ") started in " + TimeUtils.printDuration(stopWatch.taken()));
             }
             EventHelper.notifyCamelContextStarted(this);

http://git-wip-us.apache.org/repos/asf/camel/blob/6893a37f/camel-core/src/main/java/org/apache/camel/impl/DefaultRouteController.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/impl/DefaultRouteController.java b/camel-core/src/main/java/org/apache/camel/impl/DefaultRouteController.java
index ff51cf3..db10a33 100644
--- a/camel-core/src/main/java/org/apache/camel/impl/DefaultRouteController.java
+++ b/camel-core/src/main/java/org/apache/camel/impl/DefaultRouteController.java
@@ -17,6 +17,7 @@
 package org.apache.camel.impl;
 
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.List;
 import java.util.concurrent.TimeUnit;
 
@@ -104,4 +105,8 @@ public class DefaultRouteController extends org.apache.camel.support.ServiceSupp
         camelContext.resumeRoute(routeId);
     }
 
+    @Override
+    public List<Route> getControlledRoutes() {
+        return Collections.emptyList();
+    }
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/6893a37f/camel-core/src/main/java/org/apache/camel/impl/SupervisingRouteController.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/impl/SupervisingRouteController.java b/camel-core/src/main/java/org/apache/camel/impl/SupervisingRouteController.java
index aaa6796..669532e 100644
--- a/camel-core/src/main/java/org/apache/camel/impl/SupervisingRouteController.java
+++ b/camel-core/src/main/java/org/apache/camel/impl/SupervisingRouteController.java
@@ -16,7 +16,6 @@
  */
 package org.apache.camel.impl;
 
-import java.util.Collection;
 import java.util.EventObject;
 import java.util.HashMap;
 import java.util.List;
@@ -252,6 +251,13 @@ public class SupervisingRouteController extends DefaultRouteController {
         }
     }
 
+    @Override
+    public List<Route> getControlledRoutes() {
+        return routes.stream()
+            .map(RouteHolder::get)
+            .collect(Collectors.toList());
+    }
+
     // *********************************
     // Helpers
     // *********************************
@@ -432,14 +438,6 @@ public class SupervisingRouteController extends DefaultRouteController {
             routes.forEach((k, v) -> v.cancel(true));
             routes.clear();
         }
-
-        boolean isSupervising(RouteHolder route) {
-            return routes.containsKey(route);
-        }
-
-        Collection<RouteHolder> routes() {
-            return routes.keySet();
-        }
     }
 
     // *********************************
@@ -533,6 +531,11 @@ public class SupervisingRouteController extends DefaultRouteController {
     private class ManagedRoutePolicy implements RoutePolicy {
         @Override
         public void onInit(Route route) {
+            if ("false".equals(route.getRouteContext().getRoute().getAutoStartup())) {
+                LOGGER.info("Route {} has explicit auto-startup flag set to false, ignore it", route.getId());
+                return;
+            }
+
             RouteHolder holder = new RouteHolder(route, routeCount.incrementAndGet());
             if (routes.add(holder)) {
                 holder.getContext().setRouteController(SupervisingRouteController.this);

http://git-wip-us.apache.org/repos/asf/camel/blob/6893a37f/camel-core/src/main/java/org/apache/camel/spi/RouteController.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/spi/RouteController.java b/camel-core/src/main/java/org/apache/camel/spi/RouteController.java
index 0f25a2d..0e55c52 100644
--- a/camel-core/src/main/java/org/apache/camel/spi/RouteController.java
+++ b/camel-core/src/main/java/org/apache/camel/spi/RouteController.java
@@ -16,10 +16,12 @@
  */
 package org.apache.camel.spi;
 
+import java.util.List;
 import java.util.concurrent.TimeUnit;
 
 import org.apache.camel.CamelContextAware;
 import org.apache.camel.Experimental;
+import org.apache.camel.Route;
 import org.apache.camel.Service;
 
 @Experimental
@@ -38,4 +40,11 @@ public interface RouteController extends CamelContextAware, Service {
     void suspendRoute(String routeId, long timeout, TimeUnit timeUnit) throws Exception;
 
     void resumeRoute(String routeId) throws Exception;
+
+    /**
+     * Return the list of routes controlled by this controller.
+     *
+     * @return the list of controlled routes;
+     */
+    List<Route> getControlledRoutes();
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/6893a37f/examples/camel-example-spring-boot-routecontroller/src/main/java/sample/camel/ApplicationRoutes.java
----------------------------------------------------------------------
diff --git a/examples/camel-example-spring-boot-routecontroller/src/main/java/sample/camel/ApplicationRoutes.java b/examples/camel-example-spring-boot-routecontroller/src/main/java/sample/camel/ApplicationRoutes.java
index bd1473a..7115570 100644
--- a/examples/camel-example-spring-boot-routecontroller/src/main/java/sample/camel/ApplicationRoutes.java
+++ b/examples/camel-example-spring-boot-routecontroller/src/main/java/sample/camel/ApplicationRoutes.java
@@ -39,5 +39,10 @@ public class ApplicationRoutes extends RouteBuilder {
         from("undertow:http://localhost:9011")
             .id("undertow")
             .log("From undertow ...");
+
+        from("undertow:http://localhost:9012")
+            .id("undertow-2")
+            .autoStartup(false)
+            .log("From undertow ...");
     }
 }


[08/10] camel git commit: CAMEL-11641: SupervisingRouteController : backOff should be renamed deaultBackoff

Posted by lb...@apache.org.
CAMEL-11641: SupervisingRouteController : backOff should be renamed deaultBackoff


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/b3ebc7b2
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/b3ebc7b2
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/b3ebc7b2

Branch: refs/heads/master
Commit: b3ebc7b2b730ca391bc669fad491f2d20625b5db
Parents: a25eb77
Author: lburgazzoli <lb...@gmail.com>
Authored: Mon Aug 7 09:21:24 2017 +0200
Committer: lburgazzoli <lb...@gmail.com>
Committed: Tue Aug 8 13:29:28 2017 +0200

----------------------------------------------------------------------
 .../src/main/java/org/apache/camel/util/backoff/BackOff.java   | 4 ++++
 .../boot/SupervisingRouteControllerAutoConfiguration.java      | 4 ++--
 .../spring/boot/SupervisingRouteControllerConfiguration.java   | 6 +++---
 .../src/main/resources/application.properties                  | 4 ++--
 4 files changed, 11 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/b3ebc7b2/camel-core/src/main/java/org/apache/camel/util/backoff/BackOff.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/util/backoff/BackOff.java b/camel-core/src/main/java/org/apache/camel/util/backoff/BackOff.java
index f38c957..85eb5ac 100644
--- a/camel-core/src/main/java/org/apache/camel/util/backoff/BackOff.java
+++ b/camel-core/src/main/java/org/apache/camel/util/backoff/BackOff.java
@@ -133,6 +133,10 @@ public final class BackOff {
         return new Builder();
     }
 
+    public static Builder builder(BackOff template) {
+        return new Builder().read(template);
+    }
+
     /**
      * A builder for {@link BackOff}
      */

http://git-wip-us.apache.org/repos/asf/camel/blob/b3ebc7b2/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
index 7382c6f..abb747d 100644
--- 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
@@ -49,7 +49,7 @@ public class SupervisingRouteControllerAutoConfiguration {
     public RouteController routeController() {
         SupervisingRouteController controller = new SupervisingRouteController();
 
-        controller.setDefaultBackOff(configureBackOff(Optional.empty(), configuration.getBackOff()));
+        controller.setDefaultBackOff(configureBackOff(Optional.empty(), configuration.getDefaultBackOff()));
 
         for (Map.Entry<String, RouteConfiguration> entry: configuration.getRoutes().entrySet()) {
             controller.setBackOff(
@@ -65,7 +65,7 @@ public class SupervisingRouteControllerAutoConfiguration {
     }
 
     private BackOff configureBackOff(Optional<BackOff> template, BackOffConfiguration conf) {
-        final BackOff.Builder builder = template.map(t -> BackOff.builder().read(t)).orElseGet(BackOff::builder);
+        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);

http://git-wip-us.apache.org/repos/asf/camel/blob/b3ebc7b2/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
index bf68b6a..fb667b3 100644
--- 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
@@ -31,7 +31,7 @@ public class SupervisingRouteControllerConfiguration {
     /**
      * The default back-off configuration, back-off configuration for routes inherits from this default.
      */
-    private BackOffConfiguration backOff = new BackOffConfiguration();
+    private BackOffConfiguration defaultBackOff = new BackOffConfiguration();
 
     /**
      * Routes configuration.
@@ -46,8 +46,8 @@ public class SupervisingRouteControllerConfiguration {
         this.enabled = enabled;
     }
 
-    public BackOffConfiguration getBackOff() {
-        return backOff;
+    public BackOffConfiguration getDefaultBackOff() {
+        return defaultBackOff;
     }
 
     public Map<String, RouteConfiguration> getRoutes() {

http://git-wip-us.apache.org/repos/asf/camel/blob/b3ebc7b2/examples/camel-example-spring-boot-routecontroller/src/main/resources/application.properties
----------------------------------------------------------------------
diff --git a/examples/camel-example-spring-boot-routecontroller/src/main/resources/application.properties b/examples/camel-example-spring-boot-routecontroller/src/main/resources/application.properties
index 54d3318..9cd0c34 100644
--- a/examples/camel-example-spring-boot-routecontroller/src/main/resources/application.properties
+++ b/examples/camel-example-spring-boot-routecontroller/src/main/resources/application.properties
@@ -37,7 +37,7 @@ management.security.enabled = false
 camel.springboot.name = SampleSupervisingRouteController
 
 camel.supervising.controller.enabled = true
-camel.supervising.controller.back-off.delay = 5s
-camel.supervising.controller.back-off.max-attempts = 10
+camel.supervising.controller.default-back-off.delay = 5s
+camel.supervising.controller.default-back-off.max-attempts = 10
 camel.supervising.controller.routes.undertow.back-off.delay = 10s
 camel.supervising.controller.routes.undertow.back-off.max-attempts = 3


[06/10] camel git commit: CAMEL-11578: Add javadoc to util.backoff

Posted by lb...@apache.org.
CAMEL-11578: Add javadoc to util.backoff


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/04f07062
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/04f07062
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/04f07062

Branch: refs/heads/master
Commit: 04f07062eb928fe53e40362f67f42b4b53e19f00
Parents: 29a3b28
Author: lburgazzoli <lb...@gmail.com>
Authored: Mon Aug 7 08:37:04 2017 +0200
Committer: lburgazzoli <lb...@gmail.com>
Committed: Tue Aug 8 13:29:28 2017 +0200

----------------------------------------------------------------------
 .../org/apache/camel/util/backoff/BackOff.java  | 34 ++++++++++++++++++++
 .../camel/util/backoff/BackOffContext.java      | 31 +++++++++++++++++-
 .../apache/camel/util/backoff/BackOffTimer.java |  9 +++++-
 ...SupervisingRouteControllerConfiguration.java |  2 +-
 4 files changed, 73 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/04f07062/camel-core/src/main/java/org/apache/camel/util/backoff/BackOff.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/util/backoff/BackOff.java b/camel-core/src/main/java/org/apache/camel/util/backoff/BackOff.java
index 1e3d326..f38c957 100644
--- a/camel-core/src/main/java/org/apache/camel/util/backoff/BackOff.java
+++ b/camel-core/src/main/java/org/apache/camel/util/backoff/BackOff.java
@@ -21,6 +21,9 @@ import java.util.concurrent.TimeUnit;
 
 import org.apache.camel.util.ObjectHelper;
 
+/**
+ * A back-off policy.
+ */
 public final class BackOff {
     public static final long NEVER = -1L;
     public static final Duration MAX_DURATION = Duration.ofMillis(Long.MAX_VALUE);
@@ -49,10 +52,16 @@ public final class BackOff {
     // Properties
     // *************************************
 
+    /**
+     * @return the delay to wait before retry the operation.
+     */
     public Duration getDelay() {
         return delay;
     }
 
+    /**
+     * The delay to wait before retry the operation.
+     */
     public void setDelay(Duration delay) {
         this.delay = delay;
     }
@@ -61,6 +70,9 @@ public final class BackOff {
         return maxDelay;
     }
 
+    /**
+     * The maximum back-off time after which the delay is not more increased.
+     */
     public void setMaxDelay(Duration maxDelay) {
         this.maxDelay = maxDelay;
     }
@@ -69,6 +81,10 @@ public final class BackOff {
         return maxElapsedTime;
     }
 
+    /**
+     * The maximum elapsed time after which the back-off should be considered
+     * exhausted and no more attempts should be made.
+     */
     public void setMaxElapsedTime(Duration maxElapsedTime) {
         this.maxElapsedTime = maxElapsedTime;
     }
@@ -77,6 +93,12 @@ public final class BackOff {
         return maxAttempts;
     }
 
+    /**
+     * The maximum number of attempts after which the back-off should be considered
+     * exhausted and no more attempts should be made.
+     *
+     * @param maxAttempts
+     */
     public void setMaxAttempts(Long maxAttempts) {
         this.maxAttempts = maxAttempts;
     }
@@ -85,6 +107,9 @@ public final class BackOff {
         return multiplier;
     }
 
+    /**
+     * The value to multiply the current interval by for each retry attempt.
+     */
     public void setMultiplier(Double multiplier) {
         this.multiplier = multiplier;
     }
@@ -108,6 +133,9 @@ public final class BackOff {
         return new Builder();
     }
 
+    /**
+     * A builder for {@link BackOff}
+     */
     public static final class Builder {
         private Duration delay = BackOff.DEFAULT_DELAY;
         private Duration maxDelay = BackOff.MAX_DURATION;
@@ -115,6 +143,9 @@ public final class BackOff {
         private Long maxAttempts = Long.MAX_VALUE;
         private Double multiplier = BackOff.DEFAULT_MULTIPLIER;
 
+        /**
+         * Read values from the given {@link BackOff}
+         */
         public Builder read(BackOff template) {
             delay = template.delay;
             maxDelay = template.maxDelay;
@@ -174,6 +205,9 @@ public final class BackOff {
             return this;
         }
 
+        /**
+         * Build a new instance of {@link BackOff}
+         */
         public BackOff build() {
             return new BackOff(delay, maxDelay, maxElapsedTime, maxAttempts, multiplier);
         }

http://git-wip-us.apache.org/repos/asf/camel/blob/04f07062/camel-core/src/main/java/org/apache/camel/util/backoff/BackOffContext.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/util/backoff/BackOffContext.java b/camel-core/src/main/java/org/apache/camel/util/backoff/BackOffContext.java
index 502f0ad..cd46653 100644
--- a/camel-core/src/main/java/org/apache/camel/util/backoff/BackOffContext.java
+++ b/camel-core/src/main/java/org/apache/camel/util/backoff/BackOffContext.java
@@ -16,7 +16,9 @@
  */
 package org.apache.camel.util.backoff;
 
-
+/**
+ * The context associated to a back-off operation.
+ */
 public final class BackOffContext {
     private final BackOff backOff;
 
@@ -35,22 +37,37 @@ public final class BackOffContext {
     // Properties
     // *************************************
 
+    /**
+     * The back-off associated with this context.
+     */
     public BackOff backOff() {
         return backOff;
     }
 
+    /**
+     * The number of attempts so far.
+     */
     public long getCurrentAttempts() {
         return currentAttempts;
     }
 
+    /**
+     * The current computed delay.
+     */
     public long getCurrentDelay() {
         return currentDelay;
     }
 
+    /**
+     * The current elapsed time.
+     */
     public long getCurrentElapsedTime() {
         return currentElapsedTime;
     }
 
+    /**
+     * Inform if the context is exhausted thus not more attempts should be made.
+     */
     public boolean isExhausted() {
         return currentDelay == BackOff.NEVER;
     }
@@ -59,6 +76,11 @@ public final class BackOffContext {
     // Impl
     // *************************************
 
+    /**
+     * Return the number of milliseconds to wait before retrying the operation
+     * or ${@link BackOff#NEVER} to indicate that no further attempt should be
+     * made.
+     */
     public long next() {
         // A call to next when currentDelay is set to NEVER has no effects
         // as this means that either the timer is exhausted or it has explicit
@@ -83,6 +105,9 @@ public final class BackOffContext {
         return currentDelay;
     }
 
+    /**
+     * Reset the context.
+     */
     public BackOffContext reset() {
         this.currentAttempts = 0;
         this.currentDelay = 0;
@@ -91,6 +116,10 @@ public final class BackOffContext {
         return this;
     }
 
+    /**
+     * Mark the context as exhausted to indicate that no further attempt should
+     * be made.
+     */
     public BackOffContext stop() {
         this.currentAttempts = 0;
         this.currentDelay = BackOff.NEVER;

http://git-wip-us.apache.org/repos/asf/camel/blob/04f07062/camel-core/src/main/java/org/apache/camel/util/backoff/BackOffTimer.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/util/backoff/BackOffTimer.java b/camel-core/src/main/java/org/apache/camel/util/backoff/BackOffTimer.java
index d82c824..c0c035f 100644
--- a/camel-core/src/main/java/org/apache/camel/util/backoff/BackOffTimer.java
+++ b/camel-core/src/main/java/org/apache/camel/util/backoff/BackOffTimer.java
@@ -22,7 +22,10 @@ import java.util.concurrent.TimeUnit;
 
 import org.apache.camel.util.function.ThrowingFunction;
 
-
+/**
+ * A simple timer utility that use a linked {@link BackOff} to determine when
+ * a task should be executed.
+ */
 public class BackOffTimer {
     private final ScheduledExecutorService scheduler;
 
@@ -30,6 +33,10 @@ public class BackOffTimer {
         this.scheduler = scheduler;
     }
 
+    /**
+     * Schedule the given function/task to be executed some time in the future
+     * according to the given backOff.
+     */
     public CompletableFuture<BackOffContext> schedule(BackOff backOff, ThrowingFunction<BackOffContext, Boolean, Exception> function) {
         final BackOffContext context = new BackOffContext(backOff);
         final Task task = new Task(context, function);

http://git-wip-us.apache.org/repos/asf/camel/blob/04f07062/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
index 32ef447..bf68b6a 100644
--- 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
@@ -99,7 +99,7 @@ public class SupervisingRouteControllerConfiguration {
         private String maxElapsedTime;
 
         /**
-         * Teh maximum number of attempts after which the back-off is exhausted.
+         * The maximum number of attempts after which the back-off is exhausted.
          */
         private Long maxAttempts;
 


[09/10] camel git commit: CAMEL-11640: SupervisingRouteController : Add a SPI to filter routes to supervise

Posted by lb...@apache.org.
CAMEL-11640: SupervisingRouteController : Add a SPI to filter routes to supervise


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/2b832e93
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/2b832e93
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/2b832e93

Branch: refs/heads/master
Commit: 2b832e937e0a1cdd3a8037880a90d0261b0f4804
Parents: ef5aa1f
Author: lburgazzoli <lb...@gmail.com>
Authored: Mon Aug 7 12:04:27 2017 +0200
Committer: lburgazzoli <lb...@gmail.com>
Committed: Tue Aug 8 13:29:29 2017 +0200

----------------------------------------------------------------------
 .../apache/camel/impl/DefaultCamelContext.java  |  2 +-
 .../camel/impl/DefaultRouteController.java      | 12 ++--
 .../camel/impl/SupervisingRouteController.java  | 75 +++++++++++++++++++-
 .../impl/SupervisingRouteControllerFilters.java | 51 +++++++++++++
 .../org/apache/camel/spi/RouteController.java   | 15 ++--
 ...rvisingRouteControllerAutoConfiguration.java | 25 +++++--
 ...SupervisingRouteControllerConfiguration.java | 13 ++++
 .../java/sample/camel/ApplicationRoutes.java    |  8 ++-
 .../src/main/resources/application.properties   |  4 +-
 9 files changed, 177 insertions(+), 28 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/2b832e93/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java b/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
index 1856ebd..61939b8 100644
--- a/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
+++ b/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
@@ -3171,7 +3171,7 @@ public class DefaultCamelContext extends ServiceSupport implements ModelCamelCon
                     }
                 }
 
-                final List<Route> controlledRoutes = getRouteController().getControlledRoutes();
+                final Collection<Route> controlledRoutes = getRouteController().getControlledRoutes();
 
                 if (controlledRoutes.isEmpty()) {
                     log.info("Total {} routes, of which {} are started",

http://git-wip-us.apache.org/repos/asf/camel/blob/2b832e93/camel-core/src/main/java/org/apache/camel/impl/DefaultRouteController.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/impl/DefaultRouteController.java b/camel-core/src/main/java/org/apache/camel/impl/DefaultRouteController.java
index db10a33..6d46adc 100644
--- a/camel-core/src/main/java/org/apache/camel/impl/DefaultRouteController.java
+++ b/camel-core/src/main/java/org/apache/camel/impl/DefaultRouteController.java
@@ -16,9 +16,8 @@
  */
 package org.apache.camel.impl;
 
-import java.util.ArrayList;
+import java.util.Collection;
 import java.util.Collections;
-import java.util.List;
 import java.util.concurrent.TimeUnit;
 
 import org.apache.camel.CamelContext;
@@ -28,16 +27,13 @@ import org.apache.camel.spi.RouteController;
 
 @Experimental
 public class DefaultRouteController extends org.apache.camel.support.ServiceSupport implements RouteController  {
-    private final List<Route> routes;
     private CamelContext camelContext;
-
     public DefaultRouteController() {
         this(null);
     }
 
     public DefaultRouteController(CamelContext camelContext) {
         this.camelContext = camelContext;
-        this.routes = new ArrayList<>();
     }
 
     // ***************************************************
@@ -105,8 +101,12 @@ public class DefaultRouteController extends org.apache.camel.support.ServiceSupp
         camelContext.resumeRoute(routeId);
     }
 
+    // ***************************************************
+    //
+    // ***************************************************
+
     @Override
-    public List<Route> getControlledRoutes() {
+    public Collection<Route> getControlledRoutes() {
         return Collections.emptyList();
     }
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/2b832e93/camel-core/src/main/java/org/apache/camel/impl/SupervisingRouteController.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/impl/SupervisingRouteController.java b/camel-core/src/main/java/org/apache/camel/impl/SupervisingRouteController.java
index 8e5167e..3054ac4 100644
--- a/camel-core/src/main/java/org/apache/camel/impl/SupervisingRouteController.java
+++ b/camel-core/src/main/java/org/apache/camel/impl/SupervisingRouteController.java
@@ -17,6 +17,9 @@
 package org.apache.camel.impl;
 
 import java.time.Duration;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
 import java.util.EventObject;
 import java.util.HashMap;
 import java.util.List;
@@ -31,6 +34,7 @@ import java.util.concurrent.ScheduledExecutorService;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.concurrent.atomic.AtomicInteger;
+import java.util.function.Function;
 import java.util.stream.Collectors;
 
 import org.apache.camel.CamelContext;
@@ -48,6 +52,7 @@ import org.apache.camel.spi.RouteController;
 import org.apache.camel.spi.RoutePolicy;
 import org.apache.camel.spi.RoutePolicyFactory;
 import org.apache.camel.support.EventNotifierSupport;
+import org.apache.camel.util.CamelContextHelper;
 import org.apache.camel.util.ObjectHelper;
 import org.apache.camel.util.backoff.BackOff;
 import org.apache.camel.util.backoff.BackOffContext;
@@ -68,6 +73,7 @@ public class SupervisingRouteController extends DefaultRouteController {
     private final Object lock;
     private final AtomicBoolean contextStarted;
     private final AtomicInteger routeCount;
+    private final List<Filter> filters;
     private final Set<RouteHolder> routes;
     private final CamelContextStartupListener listener;
     private final RouteManager routeManager;
@@ -80,6 +86,7 @@ public class SupervisingRouteController extends DefaultRouteController {
     public SupervisingRouteController() {
         this.lock = new Object();
         this.contextStarted = new AtomicBoolean(false);
+        this.filters = new ArrayList<>();
         this.routeCount = new AtomicInteger(0);
         this.routes = new TreeSet<>();
         this.routeManager = new RouteManager();
@@ -166,6 +173,25 @@ public class SupervisingRouteController extends DefaultRouteController {
         this.initialDelay = Duration.ofMillis(initialDelay);
     }
 
+    /**
+     * Add a filter used to determine the routes to supervise.
+     */
+    public void addFilter(Filter filter) {
+        this.filters.add(filter);
+    }
+
+    /**
+     * Sets the filters user to determine the routes to supervise.
+     */
+    public void setFilters(Collection<Filter> filters) {
+        this.filters.clear();
+        this.filters.addAll(filters);
+    }
+
+    public Collection<Filter> getFilters() {
+        return Collections.unmodifiableList(filters);
+    }
+
     // *********************************
     // Lifecycle
     // *********************************
@@ -298,7 +324,7 @@ public class SupervisingRouteController extends DefaultRouteController {
     }
 
     @Override
-    public List<Route> getControlledRoutes() {
+    public Collection<Route> getControlledRoutes() {
         return routes.stream()
             .map(RouteHolder::get)
             .collect(Collectors.toList());
@@ -596,11 +622,21 @@ public class SupervisingRouteController extends DefaultRouteController {
 
         @Override
         public void onInit(Route route) {
-            if ("false".equals(route.getRouteContext().getRoute().getAutoStartup())) {
-                LOGGER.info("Route {} has explicit auto-startup flag set to false, ignore it", route.getId());
+            final String autoStartup = route.getRouteContext().getRoute().getAutoStartup();
+            if (ObjectHelper.equalIgnoreCase("false", autoStartup)) {
+                LOGGER.info("Route {} won't be supervised (reason: has explicit auto-startup flag set to false)", route.getId());
                 return;
             }
 
+            for (Filter filter : filters) {
+                FilterResult result = filter.apply(route);
+
+                if (!result.supervised()) {
+                    LOGGER.info("Route {} won't be supervised (reason: {})", route.getId(), result.reason());
+                    return;
+                }
+            }
+
             RouteHolder holder = new RouteHolder(route, routeCount.incrementAndGet());
             if (routes.add(holder)) {
                 holder.getContext().setRouteController(SupervisingRouteController.this);
@@ -702,4 +738,37 @@ public class SupervisingRouteController extends DefaultRouteController {
             }
         }
     }
+
+    // *********************************
+    // Filter
+    // *********************************
+
+    @Experimental
+    public static class FilterResult {
+        public static final FilterResult SUPERVISED = new FilterResult(true, null);
+
+        private final boolean controlled;
+        private final String reason;
+
+        public FilterResult(boolean controlled, String reason) {
+            this.controlled = controlled;
+            this.reason = reason;
+        }
+
+        public FilterResult(boolean controlled, String format, Object... args) {
+            this(controlled, String.format(format, args));
+        }
+
+        public boolean supervised() {
+            return controlled;
+        }
+
+        public String reason() {
+            return reason;
+        }
+    }
+
+    @Experimental
+    public interface Filter extends Function<Route, FilterResult> {
+    }
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/2b832e93/camel-core/src/main/java/org/apache/camel/impl/SupervisingRouteControllerFilters.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/impl/SupervisingRouteControllerFilters.java b/camel-core/src/main/java/org/apache/camel/impl/SupervisingRouteControllerFilters.java
new file mode 100644
index 0000000..43ecd6a
--- /dev/null
+++ b/camel-core/src/main/java/org/apache/camel/impl/SupervisingRouteControllerFilters.java
@@ -0,0 +1,51 @@
+/**
+ * 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;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.camel.Route;
+
+public final class SupervisingRouteControllerFilters {
+    private SupervisingRouteControllerFilters() {
+    }
+
+    public static final class BlackList implements SupervisingRouteController.Filter {
+        private final Set<String> names;
+
+        public BlackList(String name) {
+            this(Collections.singletonList(name));
+        }
+
+        public BlackList(Collection<String> names) {
+            this.names = new HashSet<>(names);
+        }
+
+        @Override
+        public SupervisingRouteController.FilterResult apply(Route route) {
+            boolean supervised = !names.contains(route.getId());
+
+            return new SupervisingRouteController.FilterResult(
+                supervised,
+                supervised ? null : "black-listed"
+            );
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/2b832e93/camel-core/src/main/java/org/apache/camel/spi/RouteController.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/spi/RouteController.java b/camel-core/src/main/java/org/apache/camel/spi/RouteController.java
index 0e55c52..d19a8a2 100644
--- a/camel-core/src/main/java/org/apache/camel/spi/RouteController.java
+++ b/camel-core/src/main/java/org/apache/camel/spi/RouteController.java
@@ -16,7 +16,7 @@
  */
 package org.apache.camel.spi;
 
-import java.util.List;
+import java.util.Collection;
 import java.util.concurrent.TimeUnit;
 
 import org.apache.camel.CamelContextAware;
@@ -26,6 +26,12 @@ import org.apache.camel.Service;
 
 @Experimental
 public interface RouteController extends CamelContextAware, Service {
+    /**
+     * Return the list of routes controlled by this controller.
+     *
+     * @return the list of controlled routes;
+     */
+    Collection<Route> getControlledRoutes();
 
     void startRoute(String routeId) throws Exception;
 
@@ -40,11 +46,4 @@ public interface RouteController extends CamelContextAware, Service {
     void suspendRoute(String routeId, long timeout, TimeUnit timeUnit) throws Exception;
 
     void resumeRoute(String routeId) throws Exception;
-
-    /**
-     * Return the list of routes controlled by this controller.
-     *
-     * @return the list of controlled routes;
-     */
-    List<Route> getControlledRoutes();
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/2b832e93/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
index 9ff36bb..0ac9994 100644
--- 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
@@ -16,11 +16,14 @@
  */
 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;
@@ -42,6 +45,8 @@ import org.springframework.context.annotation.Scope;
 public class SupervisingRouteControllerAutoConfiguration {
     @Autowired
     private SupervisingRouteControllerConfiguration configuration;
+    @Autowired(required = false)
+    private List<SupervisingRouteController.Filter> filters = Collections.emptyList();
 
     @Bean
     @Scope(ConfigurableBeanFactory.SCOPE_SINGLETON)
@@ -52,17 +57,23 @@ public class SupervisingRouteControllerAutoConfiguration {
         // 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()) {
-            controller.setBackOff(
-                entry.getKey(),
-                configureBackOff(
-                    Optional.ofNullable(controller.getDefaultBackOff()),
-                    entry.getValue().getBackOff()
-                )
-            );
+            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;

http://git-wip-us.apache.org/repos/asf/camel/blob/2b832e93/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
index 4ab2290..1c4096d 100644
--- 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
@@ -75,10 +75,23 @@ public class SupervisingRouteControllerConfiguration {
 
     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;
         }

http://git-wip-us.apache.org/repos/asf/camel/blob/2b832e93/examples/camel-example-spring-boot-routecontroller/src/main/java/sample/camel/ApplicationRoutes.java
----------------------------------------------------------------------
diff --git a/examples/camel-example-spring-boot-routecontroller/src/main/java/sample/camel/ApplicationRoutes.java b/examples/camel-example-spring-boot-routecontroller/src/main/java/sample/camel/ApplicationRoutes.java
index 7115570..fb6e2f5 100644
--- a/examples/camel-example-spring-boot-routecontroller/src/main/java/sample/camel/ApplicationRoutes.java
+++ b/examples/camel-example-spring-boot-routecontroller/src/main/java/sample/camel/ApplicationRoutes.java
@@ -41,8 +41,12 @@ public class ApplicationRoutes extends RouteBuilder {
             .log("From undertow ...");
 
         from("undertow:http://localhost:9012")
-            .id("undertow-2")
+            .id("undertow2")
             .autoStartup(false)
-            .log("From undertow ...");
+            .log("From undertow 2...");
+
+        from("undertow:http://localhost:9013")
+            .id("undertow3")
+            .log("From undertow 3...");
     }
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/2b832e93/examples/camel-example-spring-boot-routecontroller/src/main/resources/application.properties
----------------------------------------------------------------------
diff --git a/examples/camel-example-spring-boot-routecontroller/src/main/resources/application.properties b/examples/camel-example-spring-boot-routecontroller/src/main/resources/application.properties
index 10efe1c..8533f6b 100644
--- a/examples/camel-example-spring-boot-routecontroller/src/main/resources/application.properties
+++ b/examples/camel-example-spring-boot-routecontroller/src/main/resources/application.properties
@@ -19,7 +19,8 @@ debug = false
 
 logging.level.org.springframework = INFO
 logging.level.org.apache.camel.spring.boot = INFO
-logging.level.org.apache.camel.impl = DEBUG
+logging.level.org.apache.camel.impl = INFO
+logging.level.org.apache.camel.impl.SupervisingRouteController = DEBUG
 logging.level.org.apache.camel.util.backoff = DEBUG
 logging.level.sample.camel = DEBUG
 
@@ -42,3 +43,4 @@ camel.supervising.controller.default-back-off.delay = 5s
 camel.supervising.controller.default-back-off.max-attempts = 10
 camel.supervising.controller.routes.undertow.back-off.delay = 10s
 camel.supervising.controller.routes.undertow.back-off.max-attempts = 3
+camel.supervising.controller.routes.undertow3.supervise = false


[07/10] camel git commit: CAMEL-11582: SupervisingRouteController should have better INFO logging on startup

Posted by lb...@apache.org.
CAMEL-11582: SupervisingRouteController should have better INFO logging on startup


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/a25eb775
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/a25eb775
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/a25eb775

Branch: refs/heads/master
Commit: a25eb7753ab3a3e03add7455d45e4c1fadb7ab1b
Parents: 04f0706
Author: lburgazzoli <lb...@gmail.com>
Authored: Mon Aug 7 08:59:26 2017 +0200
Committer: lburgazzoli <lb...@gmail.com>
Committed: Tue Aug 8 13:29:28 2017 +0200

----------------------------------------------------------------------
 .../org/apache/camel/impl/SupervisingRouteController.java | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/a25eb775/camel-core/src/main/java/org/apache/camel/impl/SupervisingRouteController.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/impl/SupervisingRouteController.java b/camel-core/src/main/java/org/apache/camel/impl/SupervisingRouteController.java
index 669532e..01396dc 100644
--- a/camel-core/src/main/java/org/apache/camel/impl/SupervisingRouteController.java
+++ b/camel-core/src/main/java/org/apache/camel/impl/SupervisingRouteController.java
@@ -335,6 +335,12 @@ public class SupervisingRouteController extends DefaultRouteController {
                 // ignored, exception handled by startRoute
             }
         }
+
+        LOGGER.info("Total managed routes: {} of which {} successfully started and {} re-starting",
+            routes.size(),
+            routes.stream().filter(r -> r.getStatus() == ServiceStatus.Started).count(),
+            routeManager.routes.size()
+        );
     }
 
     private synchronized void stopRoutes() {
@@ -542,7 +548,7 @@ public class SupervisingRouteController extends DefaultRouteController {
                 holder.getDefinition().setAutoStartup("false");
 
                 if (contextStarted.get()) {
-                    LOGGER.debug("Context is started: attempt to start route {}", route.getId());
+                    LOGGER.info("Context is already started: attempt to start route {}", route.getId());
                     try {
                         SupervisingRouteController.this.doStartRoute(
                             holder,
@@ -553,7 +559,7 @@ public class SupervisingRouteController extends DefaultRouteController {
                         throw new RuntimeCamelException(e);
                     }
                 } else {
-                    LOGGER.debug("Context is not started: add route {} to stopped routes", holder.getId());
+                    LOGGER.info("Context is not yet started: defer route {} start", holder.getId());
                 }
             }
         }


[03/10] camel git commit: CAMEL-11581: SupervisingRouteController should have spring-boot auto configuration

Posted by lb...@apache.org.
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 <lb...@gmail.com>
Authored: Fri Aug 4 18:03:50 2017 +0200
Committer: lburgazzoli <lb...@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,\