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

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

commit fd980dbaa3878d3311fec8a237c49ed4202b6bf0
Author: Claus Ibsen <claus.ib...@gmail.com>
AuthorDate: Wed Dec 29 14:02:00 2021 +0100

    CAMEL-17384: Developer Console SPI
---
 .../AbstractCamelMicroProfileHealthCheck.java      |  4 +-
 .../services/org/apache/camel/dev-console/health   |  2 +
 .../camel/impl/console/HealthDevConsole.java       | 65 ++++++++++++++++++++++
 .../impl/console/DefaultDevConsolesLoaderTest.java |  2 +-
 .../org/apache/camel/main/BaseMainSupport.java     |  3 +-
 dsl/camel-kamelet-main/pom.xml                     | 20 ++++---
 .../java/org/apache/camel/main/KameletMain.java    |  1 +
 7 files changed, 85 insertions(+), 12 deletions(-)

diff --git 
a/components/camel-microprofile/camel-microprofile-health/src/main/java/org/apache/camel/microprofile/health/AbstractCamelMicroProfileHealthCheck.java
 
b/components/camel-microprofile/camel-microprofile-health/src/main/java/org/apache/camel/microprofile/health/AbstractCamelMicroProfileHealthCheck.java
index d573d29..56e0ebd 100644
--- 
a/components/camel-microprofile/camel-microprofile-health/src/main/java/org/apache/camel/microprofile/health/AbstractCamelMicroProfileHealthCheck.java
+++ 
b/components/camel-microprofile/camel-microprofile-health/src/main/java/org/apache/camel/microprofile/health/AbstractCamelMicroProfileHealthCheck.java
@@ -60,8 +60,8 @@ public abstract class AbstractCamelMicroProfileHealthCheck 
implements HealthChec
                 Map<String, Object> details = result.getDetails();
                 boolean enabled = true;
 
-                if (details.containsKey(AbstractHealthCheck.CHECK_ENABLED)) {
-                    enabled = (boolean) 
details.get(AbstractHealthCheck.CHECK_ENABLED);
+                if 
(details.containsKey(org.apache.camel.health.HealthCheck.CHECK_ENABLED)) {
+                    enabled = (boolean) 
details.get(org.apache.camel.health.HealthCheck.CHECK_ENABLED);
                 }
 
                 if (enabled) {
diff --git 
a/core/camel-console/src/generated/resources/META-INF/services/org/apache/camel/dev-console/health
 
b/core/camel-console/src/generated/resources/META-INF/services/org/apache/camel/dev-console/health
new file mode 100644
index 0000000..19c9da6
--- /dev/null
+++ 
b/core/camel-console/src/generated/resources/META-INF/services/org/apache/camel/dev-console/health
@@ -0,0 +1,2 @@
+# Generated by camel build tools - do NOT edit this file!
+class=org.apache.camel.impl.console.HealthDevConsole
diff --git 
a/core/camel-console/src/main/java/org/apache/camel/impl/console/HealthDevConsole.java
 
b/core/camel-console/src/main/java/org/apache/camel/impl/console/HealthDevConsole.java
new file mode 100644
index 0000000..914e6d8
--- /dev/null
+++ 
b/core/camel-console/src/main/java/org/apache/camel/impl/console/HealthDevConsole.java
@@ -0,0 +1,65 @@
+/*
+ * 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.console;
+
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.util.Collection;
+import java.util.Map;
+
+import org.apache.camel.health.HealthCheck;
+import org.apache.camel.health.HealthCheckHelper;
+import org.apache.camel.spi.annotations.DevConsole;
+
+@DevConsole("health")
+public class HealthDevConsole extends AbstractDevConsole {
+
+    public HealthDevConsole() {
+        super("camel", "health", "Health Check", "Health Check Status");
+    }
+
+    @Override
+    protected Object doCall(MediaType mediaType, Map<String, Object> options) {
+        // only text is supported
+        StringBuilder sb = new StringBuilder();
+
+        Collection<HealthCheck.Result> results = 
HealthCheckHelper.invoke(getCamelContext());
+        boolean up = results.stream().allMatch(h -> 
HealthCheck.State.UP.equals(h.getState()));
+        sb.append(String.format("Health Check Status: %s", up ? "UP" : 
"DOWN"));
+        sb.append("\n");
+
+        results.forEach(res -> {
+            boolean ok = res.getState().equals(HealthCheck.State.UP);
+            if (ok) {
+                sb.append(String.format("\n    %s: %s", 
res.getCheck().getId(), res.getState()));
+            } else {
+                String msg = res.getMessage().orElse("");
+                sb.append(String.format("\n    %s: %s (%s)", 
res.getCheck().getId(), res.getState(), msg));
+                Throwable cause = res.getError().orElse(null);
+                if (cause != null) {
+                    StringWriter sw = new StringWriter();
+                    PrintWriter pw = new PrintWriter(sw);
+                    cause.printStackTrace(pw);
+                    sb.append(pw);
+                    sb.append("\n\n");
+                }
+            }
+        });
+
+        return sb.toString();
+    }
+}
diff --git 
a/core/camel-console/src/test/java/org/apache/camel/impl/console/DefaultDevConsolesLoaderTest.java
 
b/core/camel-console/src/test/java/org/apache/camel/impl/console/DefaultDevConsolesLoaderTest.java
index 5264141..3f768ed 100644
--- 
a/core/camel-console/src/test/java/org/apache/camel/impl/console/DefaultDevConsolesLoaderTest.java
+++ 
b/core/camel-console/src/test/java/org/apache/camel/impl/console/DefaultDevConsolesLoaderTest.java
@@ -29,6 +29,6 @@ public class DefaultDevConsolesLoaderTest extends 
ContextTestSupport {
     public void testLoader() throws Exception {
         DefaultDevConsolesLoader loader = new 
DefaultDevConsolesLoader(context);
         Collection<DevConsole> col = loader.loadDevConsoles();
-        Assertions.assertEquals(3, col.size());
+        Assertions.assertTrue(col.size() > 3);
     }
 }
diff --git 
a/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java 
b/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java
index 7568ccd..b4c1954 100644
--- a/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java
+++ b/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java
@@ -831,7 +831,8 @@ public abstract class BaseMainSupport extends BaseService {
             MainSupportModelConfigurer.setThreadPoolProperties(camelContext, 
mainConfigurationProperties, threadPoolProperties,
                     mainConfigurationProperties.isAutoConfigurationFailFast(), 
autoConfiguredProperties);
         }
-        if (!healthProperties.isEmpty() || 
mainConfigurationProperties.hasHealthCheckConfiguration()) {
+        boolean hc = mainConfigurationProperties.health().getEnabled() != 
null; // health-check is enabled by default
+        if (hc || !healthProperties.isEmpty() || 
mainConfigurationProperties.hasHealthCheckConfiguration()) {
             LOG.debug("Auto-configuring HealthCheck from loaded properties: 
{}", healthProperties.size());
             setHealthCheckProperties(camelContext, healthProperties, 
mainConfigurationProperties.isAutoConfigurationFailFast(),
                     autoConfiguredProperties);
diff --git a/dsl/camel-kamelet-main/pom.xml b/dsl/camel-kamelet-main/pom.xml
index daf5105..da6f5a3 100644
--- a/dsl/camel-kamelet-main/pom.xml
+++ b/dsl/camel-kamelet-main/pom.xml
@@ -44,6 +44,14 @@
         </dependency>
         <dependency>
             <groupId>org.apache.camel</groupId>
+            <artifactId>camel-health</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.camel</groupId>
+            <artifactId>camel-console</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.camel</groupId>
             <artifactId>camel-kamelet</artifactId>
         </dependency>
         <dependency>
@@ -64,23 +72,19 @@
         </dependency>
         <dependency>
             <groupId>org.apache.camel</groupId>
-            <artifactId>camel-resourceresolver-github</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.camel</groupId>
-            <artifactId>camel-yaml-dsl</artifactId>
+            <artifactId>camel-platform-http-vertx</artifactId>
         </dependency>
         <dependency>
             <groupId>org.apache.camel</groupId>
-            <artifactId>camel-catalog</artifactId>
+            <artifactId>camel-resourceresolver-github</artifactId>
         </dependency>
         <dependency>
             <groupId>org.apache.camel</groupId>
-            <artifactId>camel-platform-http-vertx</artifactId>
+            <artifactId>camel-yaml-dsl</artifactId>
         </dependency>
         <dependency>
             <groupId>org.apache.camel</groupId>
-            <artifactId>camel-console</artifactId>
+            <artifactId>camel-catalog</artifactId>
         </dependency>
 
         <dependency>
diff --git 
a/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/KameletMain.java 
b/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/KameletMain.java
index 963c46b..addfd5f 100644
--- 
a/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/KameletMain.java
+++ 
b/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/KameletMain.java
@@ -176,6 +176,7 @@ public class KameletMain extends MainCommandLineSupport {
             configure().withDevConsoleEnabled(true);
             VertxHttpServer.registerConsole(answer);
         }
+        configure().withLoadHealthChecks(true);
 
         if (download) {
             try {

Reply via email to