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 2022/10/23 09:27:44 UTC

[camel] 05/05: CAMEL-18630: camel-jbang - Add get health command

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 814356b9e315a1529e146f2e800e6ecea68743c2
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Sun Oct 23 11:27:25 2022 +0200

    CAMEL-18630: camel-jbang - Add get health command
---
 .../jbang/core/commands/process/ListHealth.java    | 45 +++++++++++++++++-----
 1 file changed, 36 insertions(+), 9 deletions(-)

diff --git a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/process/ListHealth.java b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/process/ListHealth.java
index 9af128516c6..e42979a0569 100644
--- a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/process/ListHealth.java
+++ b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/process/ListHealth.java
@@ -113,7 +113,23 @@ public class ListHealth extends ProcessBaseCommand {
                                     ZonedDateTime zdt = ZonedDateTime.parse(time);
                                     if (zdt != null) {
                                         long delta = Math.abs(ZonedDateTime.now().until(zdt, ChronoUnit.MILLIS));
-                                        row.since = TimeUtils.printAge(delta);
+                                        row.sinceLast = TimeUtils.printAge(delta);
+                                    }
+                                }
+                                time = d.getString("success.time");
+                                if (time != null) {
+                                    ZonedDateTime zdt = ZonedDateTime.parse(time);
+                                    if (zdt != null) {
+                                        long delta = Math.abs(ZonedDateTime.now().until(zdt, ChronoUnit.MILLIS));
+                                        row.sinceSuccess = TimeUtils.printAge(delta);
+                                    }
+                                }
+                                time = d.getString("failure.time");
+                                if (time != null) {
+                                    ZonedDateTime zdt = ZonedDateTime.parse(time);
+                                    if (zdt != null) {
+                                        long delta = Math.abs(ZonedDateTime.now().until(zdt, ChronoUnit.MILLIS));
+                                        row.sinceFailure = TimeUtils.printAge(delta);
                                     }
                                 }
                             }
@@ -152,11 +168,12 @@ public class ListHealth extends ProcessBaseCommand {
                     new Column().header("STATE").headerAlign(HorizontalAlign.CENTER)
                             .dataAlign(HorizontalAlign.CENTER)
                             .with(r -> r.state),
-                    new Column().header("SINCE").headerAlign(HorizontalAlign.RIGHT)
+                    new Column().header("RATE").headerAlign(HorizontalAlign.CENTER)
                             .dataAlign(HorizontalAlign.RIGHT)
-                            .with(r -> r.since),
-                    new Column().header("TOTAL").headerAlign(HorizontalAlign.RIGHT).with(r -> r.total),
-                    new Column().header("OK/KO").headerAlign(HorizontalAlign.RIGHT).with(this::getRate),
+                            .with(this::getRate),
+                    new Column().header("SINCE").headerAlign(HorizontalAlign.CENTER)
+                            .dataAlign(HorizontalAlign.RIGHT)
+                            .with(this::getSince),
                     new Column().header("MESSAGE").dataAlign(HorizontalAlign.LEFT)
                             .maxWidth(80, OverflowBehaviour.NEWLINE)
                             .with(r -> r.message))));
@@ -204,9 +221,17 @@ public class ListHealth extends ProcessBaseCommand {
     }
 
     protected String getRate(Row r) {
-        String s1 = r.success != null && !"0".equals(r.success) ? r.success : "-";
-        String s2 = r.failure != null && !"0".equals(r.failure) ? r.failure : "-";
-        return s1 + "/" + s2;
+        String s1 = r.total != null && !"0".equals(r.total) ? r.total : "-";
+        String s2 = r.success != null && !"0".equals(r.success) ? r.success : "-";
+        String s3 = r.failure != null && !"0".equals(r.failure) ? r.failure : "-";
+        return s1 + "/" + s2 + "/" + s3;
+    }
+
+    protected String getSince(Row r) {
+        String s1 = r.sinceLast != null ? r.sinceLast : "-";
+        String s2 = r.sinceSuccess != null ? r.sinceSuccess : "-";
+        String s3 = r.sinceFailure != null ? r.sinceFailure : "-";
+        return s1 + "/" + s2 + "/" + s3;
     }
 
     private static class Row {
@@ -222,7 +247,9 @@ public class ListHealth extends ProcessBaseCommand {
         String total;
         String success;
         String failure;
-        String since;
+        String sinceLast;
+        String sinceSuccess;
+        String sinceFailure;
         String message;
     }