allthingssecurity commented on code in PR #30353:
URL: https://github.com/apache/camel/pull/30353#discussion_r4626289318


##########
core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/DefaultSupervisingRouteController.java:
##########
@@ -409,6 +409,56 @@ public void resumeRoute(String routeId) throws Exception {
         }
     }
 
+    @Override
+    public void startRouteGroup(String routeGroup) throws Exception {
+        lock.lock();
+        try {
+            List<RouteHolder> group = routesOfGroup(routeGroup);
+            for (RouteHolder route : group) {
+                // as startRoute: the controller takes care that the route is 
started, and the manual start cancels a
+                // restart task (and clears an exhausted state)
+                route.get().setRouteController(this);
+                routeManager.release(route);
+            }
+            try {
+                super.startRouteGroup(routeGroup);
+            } catch (Exception e) {
+                // as startRoute: the routes of the group that did not start 
are moved to the controller supervision,
+                // so they get (eventually) restarted
+                for (RouteHolder route : group) {
+                    if (route.getStatus().isStopped()) {
+                        LOG.debug("Route {} of route group {} failed to start 
and is moved to the controller supervision",
+                                route.getId(), routeGroup);
+                        
EventHelper.notifyRouteRestartingFailure(getCamelContext(), route.get(), 0, e, 
false);
+                        routeManager.start(route);
+                    }
+                }
+                throw e;
+            }
+        } finally {
+            lock.unlock();
+        }
+    }
+
+    @Override
+    public void stopRouteGroup(String routeGroup) throws Exception {
+        lock.lock();
+        try {
+            for (RouteHolder route : routesOfGroup(routeGroup)) {
+                // as stopRoute: a route stopped manually is no longer started 
by its restart task
+                routeManager.release(route);
+                route.get().setRouteController(null);
+            }
+            super.stopRouteGroup(routeGroup);
+        } finally {
+            lock.unlock();
+        }
+    }
+
+    private List<RouteHolder> routesOfGroup(String routeGroup) {

Review Comment:
   Thanks. I kept it on purpose, so the group operation does what the per route 
one does:
   
   - `startRoute(id)` and `stopRoute(id)` 
(DefaultSupervisingRouteController.java:306, :319) look the route up in 
`routes` and call `doStartRoute`/`doStopRoute` with no supervision check. 
Routes left out by `excludeRoutes`/`includeRoutes` are in `routes` too (onInit, 
:973 and :996, tracked in `nonSupervisedRoutes`), so a manual start or stop of 
one of them already gets the same bookkeeping, including 
`setRouteController(null)` in `doStopRoute` (:516).
   - Routes with `autoStartup=false` return early in onInit (:958) and are 
never in `routes`, so `routesOfGroup` does not touch them. 
`super.startRouteGroup` handles them as the default controller does.
   - Filtering in `routesOfGroup` would not leave the unsupervised routes 
alone: `AbstractCamelContext.startRouteGroup`/`stopRouteGroup` (:1551, :1571) 
still start and stop every route of the group. It would only give those routes 
different bookkeeping on the group path than on `startRoute(id)`.
   - `Route` has no `isSupervised()`. The controller check is the private 
`isSupervised(Route)` on `nonSupervisedRoutes` (:705).
   
   If unsupervised routes should not go to the restart task after a failed 
manual start, that is a change for `startRoute` and the group methods together, 
better as its own follow-up.
   
   _Claude Code on behalf of allthingssecurity_



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to