You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2021/11/23 09:24:00 UTC

[camel] branch main updated (645e288c -> ec85b2c)

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

davsclaus pushed a change to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git.


    from 645e288c Fixed JacksonDataformat name in tests
     new fc13464  CAMEL-17223: camel-main - durationMaxAction to control whether to shutdown or stop all routes.
     new 7313fc5  CAMEL-17223: camel-main - durationMaxAction to control whether to shutdown or stop all routes.
     new 3b71f7e  CAMEL-17223: camel-main - durationMaxAction to control whether to shutdown or stop all routes.
     new 352483b  CAMEL-17223: camel-main - durationMaxAction to control whether to shutdown or stop all routes.
     new 2477c66  CAMEL-17223: camel-main - durationMaxAction to control whether to shutdown or stop all routes.
     new dfffb97  CAMEL-17223: camel-main - durationMaxAction to control whether to shutdown or stop all routes.
     new c4b5681  Upgrade formatter-maven-plugin to 2.17.0
     new ec85b2c  CAMEL-17223: camel-main - durationMaxAction to control whether to shutdown or stop all routes.

The 8 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 camel-dependencies/pom.xml                         |  2 +-
 .../main/camel-main-configuration-metadata.json    |  1 +
 .../java/org/apache/camel/spi/RouteController.java |  7 +++
 .../camel/impl/engine/AbstractCamelContext.java    | 24 ++++++++++
 .../camel/impl/engine/DefaultRouteController.java  |  5 ++
 .../camel/impl/engine/InternalRouteController.java |  5 ++
 .../impl/lw/LightweightRuntimeCamelContext.java    |  5 ++
 .../MainConfigurationPropertiesConfigurer.java     |  6 +++
 .../camel-main-configuration-metadata.json         |  1 +
 core/camel-main/src/main/docs/main.adoc            |  3 +-
 .../camel/main/DefaultConfigurationProperties.java | 23 +++++++++
 .../camel/main/MainDurationEventNotifier.java      | 55 ++++++++++++++++++----
 .../java/org/apache/camel/main/MainSupport.java    | 17 ++++++-
 .../camel/support/RouteWatcherReloadStrategy.java  |  8 +++-
 .../apache/camel/dsl/jbang/core/commands/Run.java  | 10 ++--
 .../org/apache/camel/main/KameletMainTest.java     |  3 +-
 parent/pom.xml                                     |  2 +-
 17 files changed, 156 insertions(+), 21 deletions(-)

[camel] 06/08: CAMEL-17223: camel-main - durationMaxAction to control whether to shutdown or stop all routes.

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit dfffb9743a8e0ea649a2c10f53c60659c5138e68
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Tue Nov 23 06:40:30 2021 +0100

    CAMEL-17223: camel-main - durationMaxAction to control whether to shutdown or stop all routes.
---
 .../org/apache/camel/catalog/main/camel-main-configuration-metadata.json | 1 +
 1 file changed, 1 insertion(+)

diff --git a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/main/camel-main-configuration-metadata.json b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/main/camel-main-configuration-metadata.json
index bbb41bd..8efbdb0 100644
--- a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/main/camel-main-configuration-metadata.json
+++ b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/main/camel-main-configuration-metadata.json
@@ -28,6 +28,7 @@
     { "name": "camel.main.consumerTemplateCacheSize", "description": "Consumer template endpoints cache size.", "sourceType": "org.apache.camel.main.DefaultConfigurationProperties", "type": "integer", "javaType": "int", "defaultValue": 1000 },
     { "name": "camel.main.dumpRoutes", "description": "If dumping is enabled then Camel will during startup dump all loaded routes (incl rests and route templates) represented as XML DSL into the log. This is intended for trouble shooting or to assist during development. Sensitive information that may be configured in the route endpoints could potentially be included in the dump output and is therefore not recommended to be used for production usage. This requires to have camel-xml-jaxb  [...]
     { "name": "camel.main.durationHitExitCode", "description": "Sets the exit code for the application if duration was hit", "sourceType": "org.apache.camel.main.MainConfigurationProperties", "type": "integer", "javaType": "int" },
+    { "name": "camel.main.durationMaxAction", "description": "Controls whether the Camel application should shutdown the JVM, or stop all routes, when duration max is triggered.", "sourceType": "org.apache.camel.main.DefaultConfigurationProperties", "type": "string", "javaType": "java.lang.String", "defaultValue": "terminate", "enum": [ "shutdown", "stop" ] },
     { "name": "camel.main.durationMaxIdleSeconds", "description": "To specify for how long time in seconds Camel can be idle before automatic terminating the JVM. You can use this to run Camel for a short while.", "sourceType": "org.apache.camel.main.DefaultConfigurationProperties", "type": "integer", "javaType": "int" },
     { "name": "camel.main.durationMaxMessages", "description": "To specify how many messages to process by Camel before automatic terminating the JVM. You can use this to run Camel for a short while.", "sourceType": "org.apache.camel.main.DefaultConfigurationProperties", "type": "integer", "javaType": "int" },
     { "name": "camel.main.durationMaxSeconds", "description": "To specify for how long time in seconds to keep running the JVM before automatic terminating the JVM. You can use this to run Camel for a short while.", "sourceType": "org.apache.camel.main.DefaultConfigurationProperties", "type": "integer", "javaType": "int" },

[camel] 02/08: CAMEL-17223: camel-main - durationMaxAction to control whether to shutdown or stop all routes.

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 7313fc5ad8f0d3edd4f44967935de3aa4cfa506e
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Mon Nov 22 15:37:12 2021 +0100

    CAMEL-17223: camel-main - durationMaxAction to control whether to shutdown or stop all routes.
---
 .../src/main/java/org/apache/camel/spi/RouteController.java        | 7 +++++++
 .../java/org/apache/camel/impl/engine/AbstractCamelContext.java    | 4 ++++
 .../java/org/apache/camel/impl/engine/InternalRouteController.java | 5 +++++
 .../org/apache/camel/impl/lw/LightweightRuntimeCamelContext.java   | 5 +++++
 .../main/java/org/apache/camel/main/MainDurationEventNotifier.java | 7 +++++--
 5 files changed, 26 insertions(+), 2 deletions(-)

diff --git a/core/camel-api/src/main/java/org/apache/camel/spi/RouteController.java b/core/camel-api/src/main/java/org/apache/camel/spi/RouteController.java
index b22812f..9af937b 100644
--- a/core/camel-api/src/main/java/org/apache/camel/spi/RouteController.java
+++ b/core/camel-api/src/main/java/org/apache/camel/spi/RouteController.java
@@ -77,6 +77,13 @@ public interface RouteController extends CamelContextAware, StaticService {
     void startAllRoutes() throws Exception;
 
     /**
+     * Stops all the routes
+     *
+     * @throws Exception is thrown if a route could not be stopped for whatever reason
+     */
+    void stopAllRoutes() throws Exception;
+
+    /**
      * Indicates whether current thread is starting route(s).
      * <p/>
      * This can be useful to know by {@link LifecycleStrategy} or the likes, in case they need to react differently.
diff --git a/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java b/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java
index 5845fd9..db84220 100644
--- a/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java
+++ b/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java
@@ -1198,6 +1198,10 @@ public abstract class AbstractCamelContext extends BaseService
         internalRouteStartupManager.doStartOrResumeRoutes(routeServices, true, true, false, false);
     }
 
+    public void stopAllRoutes() throws Exception {
+        // TODO: implement me
+    }
+
     public synchronized void startRoute(String routeId) throws Exception {
         DefaultRouteError.reset(this, routeId);
 
diff --git a/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/InternalRouteController.java b/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/InternalRouteController.java
index f7f7cc8..d2219f1 100644
--- a/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/InternalRouteController.java
+++ b/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/InternalRouteController.java
@@ -73,6 +73,11 @@ class InternalRouteController implements RouteController {
     }
 
     @Override
+    public void stopAllRoutes() throws Exception {
+        abstractCamelContext.stopAllRoutes();
+    }
+
+    @Override
     public boolean isStartingRoutes() {
         return abstractCamelContext.isStartingRoutes();
     }
diff --git a/core/camel-core-engine/src/main/java/org/apache/camel/impl/lw/LightweightRuntimeCamelContext.java b/core/camel-core-engine/src/main/java/org/apache/camel/impl/lw/LightweightRuntimeCamelContext.java
index eb12bf4..d9f7f3b 100644
--- a/core/camel-core-engine/src/main/java/org/apache/camel/impl/lw/LightweightRuntimeCamelContext.java
+++ b/core/camel-core-engine/src/main/java/org/apache/camel/impl/lw/LightweightRuntimeCamelContext.java
@@ -1994,6 +1994,11 @@ public class LightweightRuntimeCamelContext implements ExtendedCamelContext, Cat
             }
 
             @Override
+            public void stopAllRoutes() throws Exception {
+                throw new UnsupportedOperationException();
+            }
+
+            @Override
             public boolean isStartingRoutes() {
                 return false;
             }
diff --git a/core/camel-main/src/main/java/org/apache/camel/main/MainDurationEventNotifier.java b/core/camel-main/src/main/java/org/apache/camel/main/MainDurationEventNotifier.java
index 586ad25..66a7432 100644
--- a/core/camel-main/src/main/java/org/apache/camel/main/MainDurationEventNotifier.java
+++ b/core/camel-main/src/main/java/org/apache/camel/main/MainDurationEventNotifier.java
@@ -160,8 +160,11 @@ public class MainDurationEventNotifier extends EventNotifierSupport {
             return;
         }
 
-        // TODO: stop all routes via shutdown strategy
-        LOG.warn("Stopping all routes!!!");
+        try {
+            camelContext.getRouteController().stopAllRoutes();
+        } catch (Exception e) {
+            LOG.warn("Error during stopping all routes. This exception is ignored.", e);
+        }
     }
 
     private void shutdownTask() {

[camel] 08/08: CAMEL-17223: camel-main - durationMaxAction to control whether to shutdown or stop all routes.

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit ec85b2c6db656a75bd91d6e9210875a94709129d
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Tue Nov 23 09:52:38 2021 +0100

    CAMEL-17223: camel-main - durationMaxAction to control whether to shutdown or stop all routes.
---
 .../org/apache/camel/impl/engine/AbstractCamelContext.java |  8 ++++++--
 .../src/main/java/org/apache/camel/main/MainSupport.java   | 14 +++++++++++++-
 2 files changed, 19 insertions(+), 3 deletions(-)

diff --git a/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java b/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java
index 0eb4402..30dbe16 100644
--- a/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java
+++ b/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java
@@ -1207,9 +1207,13 @@ public abstract class AbstractCamelContext extends BaseService
         List<RouteStartupOrder> routesOrdered = new ArrayList<>(getRouteStartupOrder());
         routesOrdered.sort(comparator);
         for (RouteStartupOrder order : routesOrdered) {
-            stopRoute(order.getRoute().getRouteId());
+            Route route = order.getRoute();
+            boolean stopped = getRouteController().getRouteStatus(route.getRouteId()).isStopped();
+            if (!stopped) {
+                stopRoute(route.getRouteId());
+            }
         }
-        // stop remainder routes
+        // stop any remainder routes
         for (Route route : getRoutes()) {
             boolean stopped = getRouteController().getRouteStatus(route.getRouteId()).isStopped();
             if (!stopped) {
diff --git a/core/camel-main/src/main/java/org/apache/camel/main/MainSupport.java b/core/camel-main/src/main/java/org/apache/camel/main/MainSupport.java
index 4d40a91..1b925d8 100644
--- a/core/camel-main/src/main/java/org/apache/camel/main/MainSupport.java
+++ b/core/camel-main/src/main/java/org/apache/camel/main/MainSupport.java
@@ -46,6 +46,7 @@ public abstract class MainSupport extends BaseMainSupport {
     private int durationMaxMessages;
     private long durationMaxSeconds;
     private int durationHitExitCode;
+    private String durationMaxAction = "shutdown";
 
     protected MainSupport(Class<?>... configurationClasses) {
         this();
@@ -108,6 +109,7 @@ public abstract class MainSupport extends BaseMainSupport {
         durationMaxMessages = mainConfigurationProperties.getDurationMaxMessages();
         durationMaxSeconds = mainConfigurationProperties.getDurationMaxSeconds();
         durationHitExitCode = mainConfigurationProperties.getDurationHitExitCode();
+        durationMaxAction = mainConfigurationProperties.getDurationMaxAction();
 
         // register main as bootstrap
         CamelContext context = getCamelContext();
@@ -304,8 +306,18 @@ public abstract class MainSupport extends BaseMainSupport {
                     LOG.info("Waiting until complete: Duration max {} seconds", sec);
                     boolean zero = shutdownStrategy.await(sec, TimeUnit.SECONDS);
                     if (!zero) {
-                        LOG.info("Duration max seconds triggering shutdown of the JVM");
+                        if ("stop".equalsIgnoreCase(durationMaxAction)) {
+                            LOG.info("Duration max seconds triggering stopping all routes");
+                            try {
+                                camelContext.getRouteController().stopAllRoutes();
+                            } catch (Exception e) {
+                                LOG.warn("Error during stopping all routes. This exception is ignored.", e);
+                            }
+                            // we are just stopping routes (not terminating JVM) so continue
+                            continue;
+                        }
                     }
+                    LOG.info("Duration max seconds triggering shutdown of the JVM");
                     exitCode.compareAndSet(UNINITIALIZED_EXIT_CODE, exit);
                     shutdownStrategy.shutdown();
                 } else if (idle > 0 || max > 0) {

[camel] 05/08: CAMEL-17223: camel-main - durationMaxAction to control whether to shutdown or stop all routes.

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 2477c66b7bcd124f24d009a2c0df28b388025d39
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Mon Nov 22 16:18:09 2021 +0100

    CAMEL-17223: camel-main - durationMaxAction to control whether to shutdown or stop all routes.
---
 .../camel/impl/engine/AbstractCamelContext.java       | 19 ++++++++++++++++---
 .../java/org/apache/camel/main/KameletMainTest.java   |  3 ++-
 2 files changed, 18 insertions(+), 4 deletions(-)

diff --git a/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java b/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java
index bc5b795..0eb4402 100644
--- a/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java
+++ b/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java
@@ -1199,9 +1199,22 @@ public abstract class AbstractCamelContext extends BaseService
     }
 
     public void stopAllRoutes() throws Exception {
-        // stop all routes
-        if (shutdownStrategy != null) {
-            shutdownStrategy.shutdown(this, getRouteStartupOrder());
+        // stop all routes in reverse order that they were started
+        Comparator<RouteStartupOrder> comparator = Comparator.comparingInt(RouteStartupOrder::getStartupOrder);
+        if (shutdownStrategy == null || shutdownStrategy.isShutdownRoutesInReverseOrder()) {
+            comparator = comparator.reversed();
+        }
+        List<RouteStartupOrder> routesOrdered = new ArrayList<>(getRouteStartupOrder());
+        routesOrdered.sort(comparator);
+        for (RouteStartupOrder order : routesOrdered) {
+            stopRoute(order.getRoute().getRouteId());
+        }
+        // stop remainder routes
+        for (Route route : getRoutes()) {
+            boolean stopped = getRouteController().getRouteStatus(route.getRouteId()).isStopped();
+            if (!stopped) {
+                stopRoute(route.getRouteId());
+            }
         }
     }
 
diff --git a/dsl/camel-kamelet-main/src/test/java/org/apache/camel/main/KameletMainTest.java b/dsl/camel-kamelet-main/src/test/java/org/apache/camel/main/KameletMainTest.java
index 82083f8..2442d1d 100644
--- a/dsl/camel-kamelet-main/src/test/java/org/apache/camel/main/KameletMainTest.java
+++ b/dsl/camel-kamelet-main/src/test/java/org/apache/camel/main/KameletMainTest.java
@@ -36,7 +36,8 @@ public class KameletMainTest {
     public void testReload() throws Exception {
         KameletMain main = new KameletMain();
         main.setDownload(true);
-        main.configure().withDurationMaxSeconds(60);
+        main.configure().withDurationMaxMessages(10);
+        main.configure().withDurationMaxAction("stop");
         main.configure().withRoutesIncludePattern("file:src/test/resources/my-route.yaml");
         main.configure().withRoutesReloadEnabled(true);
         main.configure().withRoutesReloadDirectory("src/test/resources");

[camel] 03/08: CAMEL-17223: camel-main - durationMaxAction to control whether to shutdown or stop all routes.

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 3b71f7e64c6d222b410fbb9331ceaafe8c734ef9
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Mon Nov 22 15:39:09 2021 +0100

    CAMEL-17223: camel-main - durationMaxAction to control whether to shutdown or stop all routes.
---
 .../java/org/apache/camel/impl/engine/DefaultRouteController.java    | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/DefaultRouteController.java b/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/DefaultRouteController.java
index 7245c95..eb270d2 100644
--- a/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/DefaultRouteController.java
+++ b/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/DefaultRouteController.java
@@ -95,6 +95,11 @@ public class DefaultRouteController extends ServiceSupport implements RouteContr
     }
 
     @Override
+    public void stopAllRoutes() throws Exception {
+        getInternalRouteController().stopAllRoutes();
+    }
+
+    @Override
     public boolean isStartingRoutes() {
         return getInternalRouteController().isStartingRoutes();
     }

[camel] 07/08: Upgrade formatter-maven-plugin to 2.17.0

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit c4b5681ef5e5ee5bd5b33aae96dcaba846ae3125
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Tue Nov 23 09:02:26 2021 +0100

    Upgrade formatter-maven-plugin to 2.17.0
---
 camel-dependencies/pom.xml | 2 +-
 parent/pom.xml             | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/camel-dependencies/pom.xml b/camel-dependencies/pom.xml
index 472b333..f73075f 100644
--- a/camel-dependencies/pom.xml
+++ b/camel-dependencies/pom.xml
@@ -199,7 +199,7 @@
     <flatpack-version>4.0.5</flatpack-version>
     <flink-version>1.14.0</flink-version>
     <fop-version>2.6</fop-version>
-    <formatter-maven-plugin-version>2.16.0</formatter-maven-plugin-version>
+    <formatter-maven-plugin-version>2.17.0</formatter-maven-plugin-version>
     <freemarker-version>2.3.31</freemarker-version>
     <ftpserver-version>1.1.1</ftpserver-version>
     <geronimo-annotation-1.0-spec-version>1.1.1</geronimo-annotation-1.0-spec-version>
diff --git a/parent/pom.xml b/parent/pom.xml
index 22d627a..4a047eb 100644
--- a/parent/pom.xml
+++ b/parent/pom.xml
@@ -181,7 +181,7 @@
         <flatpack-version>4.0.5</flatpack-version>
         <flink-version>1.14.0</flink-version>
         <fop-version>2.6</fop-version>
-        <formatter-maven-plugin-version>2.16.0</formatter-maven-plugin-version>
+        <formatter-maven-plugin-version>2.17.0</formatter-maven-plugin-version>
         <ftpserver-version>1.1.1</ftpserver-version>
         <freemarker-version>2.3.31</freemarker-version>
         <geronimo-annotation-1.0-spec-version>1.1.1</geronimo-annotation-1.0-spec-version>

[camel] 01/08: CAMEL-17223: camel-main - durationMaxAction to control whether to shutdown or stop all routes.

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit fc13464dd4a48150c523408bb28ce35da0760ca6
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Mon Nov 22 15:34:36 2021 +0100

    CAMEL-17223: camel-main - durationMaxAction to control whether to shutdown or stop all routes.
---
 .../MainConfigurationPropertiesConfigurer.java     |  6 +++
 .../camel-main-configuration-metadata.json         |  1 +
 core/camel-main/src/main/docs/main.adoc            |  3 +-
 .../camel/main/DefaultConfigurationProperties.java | 23 ++++++++++
 .../camel/main/MainDurationEventNotifier.java      | 52 ++++++++++++++++++----
 .../java/org/apache/camel/main/MainSupport.java    |  3 +-
 .../apache/camel/dsl/jbang/core/commands/Run.java  | 10 +++--
 7 files changed, 83 insertions(+), 15 deletions(-)

diff --git a/core/camel-main/src/generated/java/org/apache/camel/main/MainConfigurationPropertiesConfigurer.java b/core/camel-main/src/generated/java/org/apache/camel/main/MainConfigurationPropertiesConfigurer.java
index ea92db0..ca41200 100644
--- a/core/camel-main/src/generated/java/org/apache/camel/main/MainConfigurationPropertiesConfigurer.java
+++ b/core/camel-main/src/generated/java/org/apache/camel/main/MainConfigurationPropertiesConfigurer.java
@@ -57,6 +57,8 @@ public class MainConfigurationPropertiesConfigurer extends org.apache.camel.supp
         case "DumpRoutes": target.setDumpRoutes(property(camelContext, boolean.class, value)); return true;
         case "durationhitexitcode":
         case "DurationHitExitCode": target.setDurationHitExitCode(property(camelContext, int.class, value)); return true;
+        case "durationmaxaction":
+        case "DurationMaxAction": target.setDurationMaxAction(property(camelContext, java.lang.String.class, value)); return true;
         case "durationmaxidleseconds":
         case "DurationMaxIdleSeconds": target.setDurationMaxIdleSeconds(property(camelContext, int.class, value)); return true;
         case "durationmaxmessages":
@@ -266,6 +268,8 @@ public class MainConfigurationPropertiesConfigurer extends org.apache.camel.supp
         case "DumpRoutes": return boolean.class;
         case "durationhitexitcode":
         case "DurationHitExitCode": return int.class;
+        case "durationmaxaction":
+        case "DurationMaxAction": return java.lang.String.class;
         case "durationmaxidleseconds":
         case "DurationMaxIdleSeconds": return int.class;
         case "durationmaxmessages":
@@ -476,6 +480,8 @@ public class MainConfigurationPropertiesConfigurer extends org.apache.camel.supp
         case "DumpRoutes": return target.isDumpRoutes();
         case "durationhitexitcode":
         case "DurationHitExitCode": return target.getDurationHitExitCode();
+        case "durationmaxaction":
+        case "DurationMaxAction": return target.getDurationMaxAction();
         case "durationmaxidleseconds":
         case "DurationMaxIdleSeconds": return target.getDurationMaxIdleSeconds();
         case "durationmaxmessages":
diff --git a/core/camel-main/src/generated/resources/META-INF/camel-main-configuration-metadata.json b/core/camel-main/src/generated/resources/META-INF/camel-main-configuration-metadata.json
index bbb41bd..8efbdb0 100644
--- a/core/camel-main/src/generated/resources/META-INF/camel-main-configuration-metadata.json
+++ b/core/camel-main/src/generated/resources/META-INF/camel-main-configuration-metadata.json
@@ -28,6 +28,7 @@
     { "name": "camel.main.consumerTemplateCacheSize", "description": "Consumer template endpoints cache size.", "sourceType": "org.apache.camel.main.DefaultConfigurationProperties", "type": "integer", "javaType": "int", "defaultValue": 1000 },
     { "name": "camel.main.dumpRoutes", "description": "If dumping is enabled then Camel will during startup dump all loaded routes (incl rests and route templates) represented as XML DSL into the log. This is intended for trouble shooting or to assist during development. Sensitive information that may be configured in the route endpoints could potentially be included in the dump output and is therefore not recommended to be used for production usage. This requires to have camel-xml-jaxb  [...]
     { "name": "camel.main.durationHitExitCode", "description": "Sets the exit code for the application if duration was hit", "sourceType": "org.apache.camel.main.MainConfigurationProperties", "type": "integer", "javaType": "int" },
+    { "name": "camel.main.durationMaxAction", "description": "Controls whether the Camel application should shutdown the JVM, or stop all routes, when duration max is triggered.", "sourceType": "org.apache.camel.main.DefaultConfigurationProperties", "type": "string", "javaType": "java.lang.String", "defaultValue": "terminate", "enum": [ "shutdown", "stop" ] },
     { "name": "camel.main.durationMaxIdleSeconds", "description": "To specify for how long time in seconds Camel can be idle before automatic terminating the JVM. You can use this to run Camel for a short while.", "sourceType": "org.apache.camel.main.DefaultConfigurationProperties", "type": "integer", "javaType": "int" },
     { "name": "camel.main.durationMaxMessages", "description": "To specify how many messages to process by Camel before automatic terminating the JVM. You can use this to run Camel for a short while.", "sourceType": "org.apache.camel.main.DefaultConfigurationProperties", "type": "integer", "javaType": "int" },
     { "name": "camel.main.durationMaxSeconds", "description": "To specify for how long time in seconds to keep running the JVM before automatic terminating the JVM. You can use this to run Camel for a short while.", "sourceType": "org.apache.camel.main.DefaultConfigurationProperties", "type": "integer", "javaType": "int" },
diff --git a/core/camel-main/src/main/docs/main.adoc b/core/camel-main/src/main/docs/main.adoc
index 577e32e..86a90b3 100644
--- a/core/camel-main/src/main/docs/main.adoc
+++ b/core/camel-main/src/main/docs/main.adoc
@@ -21,7 +21,7 @@ The following tables lists all the options:
 
 // main options: START
 === Camel Main configurations
-The camel.main supports 101 options, which are listed below.
+The camel.main supports 102 options, which are listed below.
 
 [width="100%",cols="2,5,^1,2",options="header"]
 |===
@@ -44,6 +44,7 @@ The camel.main supports 101 options, which are listed below.
 | *camel.main.consumerTemplate{zwsp}CacheSize* | Consumer template endpoints cache size. | 1000 | int
 | *camel.main.dumpRoutes* | If dumping is enabled then Camel will during startup dump all loaded routes (incl rests and route templates) represented as XML DSL into the log. This is intended for trouble shooting or to assist during development. Sensitive information that may be configured in the route endpoints could potentially be included in the dump output and is therefore not recommended to be used for production usage. This requires to have camel-xml-jaxb on the classpath to be able [...]
 | *camel.main.durationHitExitCode* | Sets the exit code for the application if duration was hit |  | int
+| *camel.main.durationMaxAction* | Controls whether the Camel application should shutdown the JVM, or stop all routes, when duration max is triggered. | terminate | String
 | *camel.main.durationMaxIdle{zwsp}Seconds* | To specify for how long time in seconds Camel can be idle before automatic terminating the JVM. You can use this to run Camel for a short while. |  | int
 | *camel.main.durationMaxMessages* | To specify how many messages to process by Camel before automatic terminating the JVM. You can use this to run Camel for a short while. |  | int
 | *camel.main.durationMaxSeconds* | To specify for how long time in seconds to keep running the JVM before automatic terminating the JVM. You can use this to run Camel for a short while. |  | int
diff --git a/core/camel-main/src/main/java/org/apache/camel/main/DefaultConfigurationProperties.java b/core/camel-main/src/main/java/org/apache/camel/main/DefaultConfigurationProperties.java
index 649483c..9bb457b 100644
--- a/core/camel-main/src/main/java/org/apache/camel/main/DefaultConfigurationProperties.java
+++ b/core/camel-main/src/main/java/org/apache/camel/main/DefaultConfigurationProperties.java
@@ -37,6 +37,8 @@ public abstract class DefaultConfigurationProperties<T> {
     private int durationMaxSeconds;
     private int durationMaxIdleSeconds;
     private int durationMaxMessages;
+    @Metadata(defaultValue = "terminate", enums = "shutdown,stop")
+    private String durationMaxAction = "shutdown";
     private int shutdownTimeout = 45;
     private boolean shutdownSuppressLoggingOnTimeout;
     private boolean shutdownNowOnTimeout = true;
@@ -195,6 +197,18 @@ public abstract class DefaultConfigurationProperties<T> {
         this.durationMaxMessages = durationMaxMessages;
     }
 
+    public String getDurationMaxAction() {
+        return durationMaxAction;
+    }
+
+    /**
+     * Controls whether the Camel application should shutdown the JVM, or stop all routes, when duration max is
+     * triggered.
+     */
+    public void setDurationMaxAction(String durationMaxAction) {
+        this.durationMaxAction = durationMaxAction;
+    }
+
     public int getShutdownTimeout() {
         return shutdownTimeout;
     }
@@ -1421,6 +1435,15 @@ public abstract class DefaultConfigurationProperties<T> {
     }
 
     /**
+     * Controls whether the Camel application should shutdown the JVM, or stop all routes, when duration max is
+     * triggered.
+     */
+    public T withDurationMaxAction(String durationMaxAction) {
+        this.durationMaxAction = durationMaxAction;
+        return (T) this;
+    }
+
+    /**
      * Timeout in seconds to graceful shutdown Camel.
      */
     public T withShutdownTimeout(int shutdownTimeout) {
diff --git a/core/camel-main/src/main/java/org/apache/camel/main/MainDurationEventNotifier.java b/core/camel-main/src/main/java/org/apache/camel/main/MainDurationEventNotifier.java
index 699669f..586ad25 100644
--- a/core/camel-main/src/main/java/org/apache/camel/main/MainDurationEventNotifier.java
+++ b/core/camel-main/src/main/java/org/apache/camel/main/MainDurationEventNotifier.java
@@ -33,8 +33,8 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 /**
- * A {@link org.apache.camel.spi.EventNotifier} to trigger shutdown of the Main JVM when maximum number of messages has
- * been processed.
+ * A {@link org.apache.camel.spi.EventNotifier} to trigger (shutdown of the Main JVM, or stopping all routes) when
+ * maximum number of messages has been processed.
  */
 public class MainDurationEventNotifier extends EventNotifierSupport {
 
@@ -45,6 +45,7 @@ public class MainDurationEventNotifier extends EventNotifierSupport {
     private final MainShutdownStrategy shutdownStrategy;
     private final boolean stopCamelContext;
     private final boolean restartDuration;
+    private final String action;
     private final AtomicInteger doneMessages;
 
     private volatile StopWatch watch;
@@ -52,13 +53,14 @@ public class MainDurationEventNotifier extends EventNotifierSupport {
 
     public MainDurationEventNotifier(CamelContext camelContext, int maxMessages, long maxIdleSeconds,
                                      MainShutdownStrategy shutdownStrategy, boolean stopCamelContext,
-                                     boolean restartDuration) {
+                                     boolean restartDuration, String action) {
         this.camelContext = camelContext;
         this.maxMessages = maxMessages;
         this.maxIdleSeconds = maxIdleSeconds;
         this.shutdownStrategy = shutdownStrategy;
         this.stopCamelContext = stopCamelContext;
         this.restartDuration = restartDuration;
+        this.action = action.toLowerCase();
         this.doneMessages = new AtomicInteger();
     }
 
@@ -98,9 +100,16 @@ public class MainDurationEventNotifier extends EventNotifierSupport {
             LOG.trace("Duration max messages check {} >= {} -> {}", doneMessages.get(), maxMessages, result);
 
             if (result && shutdownStrategy.isRunAllowed()) {
-                LOG.info("Duration max messages triggering shutdown of the JVM");
-                // use thread to stop Camel as otherwise we would block current thread
-                camelContext.getExecutorServiceManager().newThread("CamelMainShutdownCamelContext", this::shutdownTask).start();
+                if ("shutdown".equalsIgnoreCase(action)) {
+                    LOG.info("Duration max messages triggering shutdown of the JVM");
+                    // use thread to shutdown Camel as otherwise we would block current thread
+                    camelContext.getExecutorServiceManager().newThread("CamelMainShutdownCamelContext", this::shutdownTask)
+                            .start();
+                } else if ("stop".equalsIgnoreCase(action)) {
+                    LOG.info("Duration max messages triggering stopping all routes");
+                    // use thread to stop routes as otherwise we would block current thread
+                    camelContext.getExecutorServiceManager().newThread("CamelMainShutdownCamelContext", this::stopTask).start();
+                }
             }
         }
 
@@ -125,6 +134,15 @@ public class MainDurationEventNotifier extends EventNotifierSupport {
     }
 
     @Override
+    protected void doInit() throws Exception {
+        super.doInit();
+
+        if (!action.equals("shutdown") && !action.equals("stop")) {
+            throw new IllegalArgumentException("Unknown action: " + action);
+        }
+    }
+
+    @Override
     protected void doStart() throws Exception {
         if (maxIdleSeconds > 0) {
             // we only start watch when Camel is started
@@ -136,6 +154,16 @@ public class MainDurationEventNotifier extends EventNotifierSupport {
         }
     }
 
+    private void stopTask() {
+        // don't run the task if shutdown is in process
+        if (!shutdownStrategy.isRunAllowed()) {
+            return;
+        }
+
+        // TODO: stop all routes via shutdown strategy
+        LOG.warn("Stopping all routes!!!");
+    }
+
     private void shutdownTask() {
         // don't run the task if shutdown is in process
         if (!shutdownStrategy.isRunAllowed()) {
@@ -183,9 +211,15 @@ public class MainDurationEventNotifier extends EventNotifierSupport {
         LOG.trace("Duration max idle check {} >= {} -> {}", seconds, maxIdleSeconds, result);
 
         if (result && shutdownStrategy.isRunAllowed()) {
-            LOG.info("Duration max idle triggering shutdown of the JVM");
-            // use thread to stop Camel as otherwise we would block current thread
-            camelContext.getExecutorServiceManager().newThread("CamelMainShutdownCamelContext", this::shutdownTask).start();
+            if ("shutdown".equals(action)) {
+                LOG.info("Duration max idle triggering shutdown of the JVM");
+                // use thread to stop Camel as otherwise we would block current thread
+                camelContext.getExecutorServiceManager().newThread("CamelMainShutdownCamelContext", this::shutdownTask).start();
+            } else if ("stop".equals(action)) {
+                LOG.info("Duration max idle triggering stopping all routes");
+                // use thread to stop Camel as otherwise we would block current thread
+                camelContext.getExecutorServiceManager().newThread("CamelMainShutdownCamelContext", this::stopTask).start();
+            }
         }
     }
 }
diff --git a/core/camel-main/src/main/java/org/apache/camel/main/MainSupport.java b/core/camel-main/src/main/java/org/apache/camel/main/MainSupport.java
index 6b9e13a..4d40a91 100644
--- a/core/camel-main/src/main/java/org/apache/camel/main/MainSupport.java
+++ b/core/camel-main/src/main/java/org/apache/camel/main/MainSupport.java
@@ -281,7 +281,8 @@ public abstract class MainSupport extends BaseMainSupport {
                     mainConfigurationProperties.getDurationMaxIdleSeconds(),
                     shutdownStrategy,
                     true,
-                    mainConfigurationProperties.isRoutesReloadRestartDuration());
+                    mainConfigurationProperties.isRoutesReloadRestartDuration(),
+                    mainConfigurationProperties.getDurationMaxAction());
 
             // register our event notifier
             ServiceHelper.startService(notifier);
diff --git a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/Run.java b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/Run.java
index 8c83bfd..4b0999b 100644
--- a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/Run.java
+++ b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/Run.java
@@ -142,7 +142,7 @@ class Run implements Callable<Integer> {
         if (!ResourceHelper.hasScheme(binding) && !binding.startsWith("github:")) {
             binding = "file:" + binding;
         }
-        main.addInitialProperty("camel.main.routes-include-pattern", binding);
+        main.addInitialProperty("camel.main.routesIncludePattern", binding);
 
         if (binding.startsWith("file:")) {
             // check if file exist
@@ -154,10 +154,12 @@ class Run implements Callable<Integer> {
 
             // we can only reload if file based
             if (reload) {
-                main.addInitialProperty("camel.main.routes-reload-enabled", "true");
-                main.addInitialProperty("camel.main.routes-reload-directory", ".");
+                main.addInitialProperty("camel.main.routesReloadEnabled", "true");
+                main.addInitialProperty("camel.main.routesReloadDirectory", ".");
                 // skip file: as prefix
-                main.addInitialProperty("camel.main.routes-reload-pattern", binding.substring(5));
+                main.addInitialProperty("camel.main.routesReloadPattern", binding.substring(5));
+                // do not shutdown the JVM but stop routes when max duration is triggered
+                main.addInitialProperty("camel.main.durationMaxAction", "stop");
             }
         }
 

[camel] 04/08: CAMEL-17223: camel-main - durationMaxAction to control whether to shutdown or stop all routes.

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 352483bda8d30f182c13018168cced33bc4e94c7
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Mon Nov 22 16:02:47 2021 +0100

    CAMEL-17223: camel-main - durationMaxAction to control whether to shutdown or stop all routes.
---
 .../java/org/apache/camel/impl/engine/AbstractCamelContext.java   | 5 ++++-
 .../java/org/apache/camel/support/RouteWatcherReloadStrategy.java | 8 ++++++--
 2 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java b/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java
index db84220..bc5b795 100644
--- a/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java
+++ b/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java
@@ -1199,7 +1199,10 @@ public abstract class AbstractCamelContext extends BaseService
     }
 
     public void stopAllRoutes() throws Exception {
-        // TODO: implement me
+        // stop all routes
+        if (shutdownStrategy != null) {
+            shutdownStrategy.shutdown(this, getRouteStartupOrder());
+        }
     }
 
     public synchronized void startRoute(String routeId) throws Exception {
diff --git a/core/camel-support/src/main/java/org/apache/camel/support/RouteWatcherReloadStrategy.java b/core/camel-support/src/main/java/org/apache/camel/support/RouteWatcherReloadStrategy.java
index 7007540..3555d55 100644
--- a/core/camel-support/src/main/java/org/apache/camel/support/RouteWatcherReloadStrategy.java
+++ b/core/camel-support/src/main/java/org/apache/camel/support/RouteWatcherReloadStrategy.java
@@ -118,8 +118,12 @@ public class RouteWatcherReloadStrategy extends FileWatcherResourceReloadStrateg
                     // should all existing routes be stopped and removed first?
                     if (removeAllRoutes) {
                         for (Route route : getCamelContext().getRoutes()) {
-                            getCamelContext().getRouteController().stopRoute(route.getRouteId());
-                            getCamelContext().removeRoute(route.getRouteId());
+                            boolean stopped
+                                    = getCamelContext().getRouteController().getRouteStatus(route.getRouteId()).isStopped();
+                            if (!stopped) {
+                                getCamelContext().getRouteController().stopRoute(route.getRouteId());
+                                getCamelContext().removeRoute(route.getRouteId());
+                            }
                         }
                     }
                     Set<String> ids