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

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


The following commit(s) were added to refs/heads/main by this push:
     new cd288563b7 Restore capability to disable automatic startup of the 
Camel Quarkus runtime
cd288563b7 is described below

commit cd288563b701a73980b1602adb86f53735d83d07
Author: James Netherton <jamesnether...@gmail.com>
AuthorDate: Mon Oct 28 10:46:41 2024 +0000

    Restore capability to disable automatic startup of the Camel Quarkus runtime
    
    Fixes #6067
---
 .../ROOT/pages/reference/extensions/core.adoc      | 12 ++---
 .../core/deployment/CamelBootstrapProcessor.java   |  7 ++-
 .../camel/quarkus/core/CamelBootstrapRecorder.java | 17 +++---
 .../org/apache/camel/quarkus/core/CamelConfig.java | 20 -------
 .../apache/camel/quarkus/core/CamelRuntime.java    |  2 +-
 .../{CamelRuntime.java => CamelRuntimeConfig.java} | 32 +++++++----
 .../camel/quarkus/main/CamelMainRuntime.java       |  5 +-
 .../camel/quarkus/main/CoreMainResource.java       | 17 ++++++
 .../camel/quarkus/main/BootstrapDisabledIT.java    | 15 ++----
 .../camel/quarkus/main/BootstrapDisabledTest.java  | 62 ++++++++++++++++++++++
 10 files changed, 132 insertions(+), 57 deletions(-)

diff --git a/docs/modules/ROOT/pages/reference/extensions/core.adoc 
b/docs/modules/ROOT/pages/reference/extensions/core.adoc
index b09867f1b8..c028d95119 100644
--- a/docs/modules/ROOT/pages/reference/extensions/core.adoc
+++ b/docs/modules/ROOT/pages/reference/extensions/core.adoc
@@ -130,12 +130,6 @@ As such, the class 
`PropertiesCustomBeanWithSetterInjection` needs to be link:ht
 | Configuration property | Type | Default
 
 
-|icon:lock[title=Fixed at build time] 
[[quarkus.camel.bootstrap.enabled]]`link:#quarkus.camel.bootstrap.enabled[quarkus.camel.bootstrap.enabled]`
-
-When set to true, the `CamelRuntime` will be started automatically.
-| `boolean`
-| `true`
-
 |icon:lock[title=Fixed at build time] 
[[quarkus.camel.service.discovery.exclude-patterns]]`link:#quarkus.camel.service.discovery.exclude-patterns[quarkus.camel.service.discovery.exclude-patterns]`
 
 A comma-separated list of Ant-path style patterns to match Camel service 
definition files in the classpath. The
@@ -481,6 +475,12 @@ throws a `RuntimeException` ignore - Suppresses any 
warnings and the application
 Prints the `CamelMain` usage statement but allows the application startup to 
proceed as normal
 | `fail`, `warn`, `ignore`
 | `warn`
+
+| 
[[quarkus.camel.bootstrap.enabled]]`link:#quarkus.camel.bootstrap.enabled[quarkus.camel.bootstrap.enabled]`
+
+When set to true, the {@link CamelRuntime} will be started automatically.
+| `boolean`
+| `true`
 |===
 
 [.configuration-legend]
diff --git 
a/extensions-core/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/CamelBootstrapProcessor.java
 
b/extensions-core/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/CamelBootstrapProcessor.java
index d0d675f8d1..c91e56a80d 100644
--- 
a/extensions-core/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/CamelBootstrapProcessor.java
+++ 
b/extensions-core/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/CamelBootstrapProcessor.java
@@ -26,6 +26,7 @@ import io.quarkus.deployment.builditem.ServiceStartBuildItem;
 import io.quarkus.deployment.builditem.ShutdownContextBuildItem;
 import io.quarkus.runtime.ShutdownContext;
 import org.apache.camel.quarkus.core.CamelBootstrapRecorder;
+import org.apache.camel.quarkus.core.CamelRuntimeConfig;
 import 
org.apache.camel.quarkus.core.deployment.spi.CamelBootstrapCompletedBuildItem;
 import org.apache.camel.quarkus.core.deployment.spi.CamelRuntimeBuildItem;
 import org.apache.camel.quarkus.core.deployment.util.CamelQuarkusVersion;
@@ -39,6 +40,7 @@ class CamelBootstrapProcessor {
      * @param commandLineArguments a reference to the raw command line 
arguments as they were passed to the application.
      * @param shutdown             a reference to a {@link ShutdownContext} 
used tor register the Camel's related shutdown
      *                             tasks.
+     * @param camelRuntimeConfig   The {@link CamelRuntimeConfig} instance.
      */
     @BuildStep
     @Record(value = ExecutionTime.RUNTIME_INIT)
@@ -48,11 +50,12 @@ class CamelBootstrapProcessor {
             CamelRuntimeBuildItem runtime,
             RawCommandLineArgumentsBuildItem commandLineArguments,
             ShutdownContextBuildItem shutdown,
-            BuildProducer<ServiceStartBuildItem> serviceStartBuildItems) {
+            BuildProducer<ServiceStartBuildItem> serviceStartBuildItems,
+            CamelRuntimeConfig camelRuntimeConfig) {
 
         recorder.addShutdownTask(shutdown, runtime.runtime());
         if (runtime.isAutoStartup()) {
-            recorder.start(runtime.runtime(), commandLineArguments, 
CamelQuarkusVersion.getVersion());
+            recorder.start(camelRuntimeConfig, runtime.runtime(), 
commandLineArguments, CamelQuarkusVersion.getVersion());
         }
         /* Make sure that Quarkus orders this method before starting to serve 
HTTP endpoints.
          * Otherwise first requests might reach Camel context in a 
non-yet-started state. */
diff --git 
a/extensions-core/core/runtime/src/main/java/org/apache/camel/quarkus/core/CamelBootstrapRecorder.java
 
b/extensions-core/core/runtime/src/main/java/org/apache/camel/quarkus/core/CamelBootstrapRecorder.java
index 5b679fd5f7..913e197562 100644
--- 
a/extensions-core/core/runtime/src/main/java/org/apache/camel/quarkus/core/CamelBootstrapRecorder.java
+++ 
b/extensions-core/core/runtime/src/main/java/org/apache/camel/quarkus/core/CamelBootstrapRecorder.java
@@ -38,13 +38,16 @@ public class CamelBootstrapRecorder {
         });
     }
 
-    public void start(RuntimeValue<CamelRuntime> runtime, Supplier<String[]> 
arguments, String camelQuarkusVersion) {
-        try {
-            Logger logger = Logger.getLogger(CamelBootstrapRecorder.class);
-            logger.infof("Apache Camel Quarkus %s is starting", 
camelQuarkusVersion);
-            runtime.getValue().start(arguments.get());
-        } catch (Exception e) {
-            throw new RuntimeException(e);
+    public void start(CamelRuntimeConfig camelRuntimeConfig, 
RuntimeValue<CamelRuntime> runtime, Supplier<String[]> arguments,
+            String camelQuarkusVersion) {
+        if (camelRuntimeConfig.bootstrap.enabled) {
+            try {
+                Logger logger = Logger.getLogger(CamelBootstrapRecorder.class);
+                logger.infof("Apache Camel Quarkus %s is starting", 
camelQuarkusVersion);
+                runtime.getValue().start(arguments.get());
+            } catch (Exception e) {
+                throw new RuntimeException(e);
+            }
         }
     }
 }
diff --git 
a/extensions-core/core/runtime/src/main/java/org/apache/camel/quarkus/core/CamelConfig.java
 
b/extensions-core/core/runtime/src/main/java/org/apache/camel/quarkus/core/CamelConfig.java
index 49e54ffe0c..f341f9dfeb 100644
--- 
a/extensions-core/core/runtime/src/main/java/org/apache/camel/quarkus/core/CamelConfig.java
+++ 
b/extensions-core/core/runtime/src/main/java/org/apache/camel/quarkus/core/CamelConfig.java
@@ -32,14 +32,6 @@ public class CamelConfig {
         fail, warn, ignore
     }
 
-    /**
-     * Build time configuration options for `CamelRuntime` bootstrap.
-     *
-     * @asciidoclet
-     */
-    @ConfigItem
-    public BootstrapConfig bootstrap;
-
     /**
      * Build time configuration options for Camel services.
      *
@@ -121,18 +113,6 @@ public class CamelConfig {
     @ConfigItem
     public TypeConverterConfig typeConverter;
 
-    @ConfigGroup
-    public static class BootstrapConfig {
-
-        /**
-         * When set to true, the `CamelRuntime` will be started automatically.
-         *
-         * @asciidoclet
-         */
-        @ConfigItem(defaultValue = "true")
-        public boolean enabled;
-    }
-
     @ConfigGroup
     public static class RoutesDiscoveryConfig {
 
diff --git 
a/extensions-core/core/runtime/src/main/java/org/apache/camel/quarkus/core/CamelRuntime.java
 
b/extensions-core/core/runtime/src/main/java/org/apache/camel/quarkus/core/CamelRuntime.java
index 933ec1402b..ae1b1500e5 100644
--- 
a/extensions-core/core/runtime/src/main/java/org/apache/camel/quarkus/core/CamelRuntime.java
+++ 
b/extensions-core/core/runtime/src/main/java/org/apache/camel/quarkus/core/CamelRuntime.java
@@ -22,7 +22,7 @@ import org.apache.camel.spi.HasCamelContext;
  * Represent a runnable Camel instance.
  */
 public interface CamelRuntime extends HasCamelContext {
-    void start(String[] args);
+    void start(String... args);
 
     void stop();
 
diff --git 
a/extensions-core/core/runtime/src/main/java/org/apache/camel/quarkus/core/CamelRuntime.java
 
b/extensions-core/core/runtime/src/main/java/org/apache/camel/quarkus/core/CamelRuntimeConfig.java
similarity index 53%
copy from 
extensions-core/core/runtime/src/main/java/org/apache/camel/quarkus/core/CamelRuntime.java
copy to 
extensions-core/core/runtime/src/main/java/org/apache/camel/quarkus/core/CamelRuntimeConfig.java
index 933ec1402b..7c22fb2c39 100644
--- 
a/extensions-core/core/runtime/src/main/java/org/apache/camel/quarkus/core/CamelRuntime.java
+++ 
b/extensions-core/core/runtime/src/main/java/org/apache/camel/quarkus/core/CamelRuntimeConfig.java
@@ -16,15 +16,29 @@
  */
 package org.apache.camel.quarkus.core;
 
-import org.apache.camel.spi.HasCamelContext;
+import io.quarkus.runtime.annotations.ConfigGroup;
+import io.quarkus.runtime.annotations.ConfigItem;
+import io.quarkus.runtime.annotations.ConfigPhase;
+import io.quarkus.runtime.annotations.ConfigRoot;
 
-/**
- * Represent a runnable Camel instance.
- */
-public interface CamelRuntime extends HasCamelContext {
-    void start(String[] args);
-
-    void stop();
+@ConfigRoot(name = "camel", phase = ConfigPhase.RUN_TIME)
+public class CamelRuntimeConfig {
+    /**
+     * Runtime configuration options for {@link CamelRuntime} bootstrap.
+     *
+     * @asciidoclet
+     */
+    @ConfigItem
+    public BootstrapConfig bootstrap;
 
-    int waitForExit();
+    @ConfigGroup
+    public static class BootstrapConfig {
+        /**
+         * When set to true, the {@link CamelRuntime} will be started 
automatically.
+         *
+         * @asciidoclet
+         */
+        @ConfigItem(defaultValue = "true")
+        public boolean enabled;
+    }
 }
diff --git 
a/extensions-core/core/runtime/src/main/java/org/apache/camel/quarkus/main/CamelMainRuntime.java
 
b/extensions-core/core/runtime/src/main/java/org/apache/camel/quarkus/main/CamelMainRuntime.java
index dd9b329f28..720dda9953 100644
--- 
a/extensions-core/core/runtime/src/main/java/org/apache/camel/quarkus/main/CamelMainRuntime.java
+++ 
b/extensions-core/core/runtime/src/main/java/org/apache/camel/quarkus/main/CamelMainRuntime.java
@@ -68,7 +68,10 @@ public class CamelMainRuntime implements CamelRuntime {
 
     @Override
     public void stop() {
-        main.stop();
+        if (!main.isStopped()) {
+            main.stop();
+        }
+
         /* Wait till the Camel shutdown is finished in camel-main thread 
started in start(String[]) above */
         final Thread worker = this.mainThread;
         if (worker != null) {
diff --git 
a/integration-tests/main/src/main/java/org/apache/camel/quarkus/main/CoreMainResource.java
 
b/integration-tests/main/src/main/java/org/apache/camel/quarkus/main/CoreMainResource.java
index 40c4887851..b885520593 100644
--- 
a/integration-tests/main/src/main/java/org/apache/camel/quarkus/main/CoreMainResource.java
+++ 
b/integration-tests/main/src/main/java/org/apache/camel/quarkus/main/CoreMainResource.java
@@ -41,6 +41,7 @@ import org.apache.camel.ServiceStatus;
 import org.apache.camel.component.log.LogComponent;
 import org.apache.camel.impl.debugger.DebuggerJmxConnectorService;
 import org.apache.camel.model.ModelCamelContext;
+import org.apache.camel.quarkus.core.CamelRuntime;
 import org.apache.camel.quarkus.core.FastFactoryFinderResolver;
 import org.apache.camel.quarkus.it.support.typeconverter.MyPair;
 import org.apache.camel.reactive.vertx.VertXReactiveExecutor;
@@ -63,6 +64,9 @@ public class CoreMainResource {
     @Inject
     CamelMain main;
 
+    @Inject
+    CamelRuntime camelRuntime;
+
     @Path("/property/{name}")
     @GET
     @Produces(MediaType.TEXT_PLAIN)
@@ -310,4 +314,17 @@ public class CoreMainResource {
             contextReloadStrategy.onReload(this);
         }
     }
+
+    @Path("/runtime/status")
+    @GET
+    @Produces(MediaType.TEXT_PLAIN)
+    public String runtimeStatus() {
+        return main.getStatus().name();
+    }
+
+    @Path("/runtime/start")
+    @POST
+    public void runtimeStart() {
+        camelRuntime.start();
+    }
 }
diff --git 
a/extensions-core/core/runtime/src/main/java/org/apache/camel/quarkus/core/CamelRuntime.java
 
b/integration-tests/main/src/test/java/org/apache/camel/quarkus/main/BootstrapDisabledIT.java
similarity index 75%
copy from 
extensions-core/core/runtime/src/main/java/org/apache/camel/quarkus/core/CamelRuntime.java
copy to 
integration-tests/main/src/test/java/org/apache/camel/quarkus/main/BootstrapDisabledIT.java
index 933ec1402b..1bbbbb2d34 100644
--- 
a/extensions-core/core/runtime/src/main/java/org/apache/camel/quarkus/core/CamelRuntime.java
+++ 
b/integration-tests/main/src/test/java/org/apache/camel/quarkus/main/BootstrapDisabledIT.java
@@ -14,17 +14,10 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.camel.quarkus.core;
+package org.apache.camel.quarkus.main;
 
-import org.apache.camel.spi.HasCamelContext;
+import io.quarkus.test.junit.QuarkusIntegrationTest;
 
-/**
- * Represent a runnable Camel instance.
- */
-public interface CamelRuntime extends HasCamelContext {
-    void start(String[] args);
-
-    void stop();
-
-    int waitForExit();
+@QuarkusIntegrationTest
+class BootstrapDisabledIT extends BootstrapDisabledTest {
 }
diff --git 
a/integration-tests/main/src/test/java/org/apache/camel/quarkus/main/BootstrapDisabledTest.java
 
b/integration-tests/main/src/test/java/org/apache/camel/quarkus/main/BootstrapDisabledTest.java
new file mode 100644
index 0000000000..424e5a41c4
--- /dev/null
+++ 
b/integration-tests/main/src/test/java/org/apache/camel/quarkus/main/BootstrapDisabledTest.java
@@ -0,0 +1,62 @@
+/*
+ * 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.quarkus.main;
+
+import java.time.Duration;
+import java.util.Map;
+
+import io.quarkus.test.junit.QuarkusTest;
+import io.quarkus.test.junit.QuarkusTestProfile;
+import io.quarkus.test.junit.TestProfile;
+import io.restassured.RestAssured;
+import org.apache.camel.ServiceStatus;
+import org.junit.jupiter.api.Test;
+
+import static org.awaitility.Awaitility.await;
+import static org.hamcrest.Matchers.is;
+
+@QuarkusTest
+@TestProfile(BootstrapDisabledTest.BootstrapDisabledTestProfile.class)
+class BootstrapDisabledTest {
+    @Test
+    void initializeManualRuntimeBootstrap() {
+        // Initial runtime state should be stopped
+        RestAssured.get("/test/runtime/status")
+                .then()
+                .statusCode(200)
+                .body(is(ServiceStatus.Stopped.name()));
+
+        // Ensure the runtime can be started manually
+        RestAssured.post("/test/runtime/start")
+                .then()
+                .statusCode(204);
+
+        
await().atMost(Duration.ofSeconds(10)).pollDelay(Duration.ofMillis(100)).untilAsserted(()
 -> {
+            RestAssured.get("/test/runtime/status")
+                    .then()
+                    .statusCode(200)
+                    .body(is(ServiceStatus.Started.name()));
+        });
+    }
+
+    public static final class BootstrapDisabledTestProfile implements 
QuarkusTestProfile {
+        @Override
+        public Map<String, String> getConfigOverrides() {
+            return Map.of("quarkus.camel.bootstrap.enabled", "false");
+        }
+    }
+}

Reply via email to