gnodet-bot commented on code in PR #29883:
URL: https://github.com/apache/camel/pull/29883#discussion_r4568438363


##########
dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/process/IntegrationStatus.java:
##########
@@ -0,0 +1,598 @@
+/*
+ * 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.dsl.jbang.core.commands.process;
+
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Set;
+import java.util.StringJoiner;
+
+import org.aesh.command.CommandDefinition;
+import org.aesh.command.option.Argument;
+import org.aesh.command.option.Option;
+import org.apache.camel.dsl.jbang.core.commands.CamelJBangMain;
+import org.apache.camel.dsl.jbang.core.commands.ai.ReloadOutcome;
+import org.apache.camel.dsl.jbang.core.common.CliException;
+import org.apache.camel.dsl.jbang.core.common.CliExitCode;
+import org.apache.camel.dsl.jbang.core.common.JsonOutput;
+import org.apache.camel.dsl.jbang.core.common.ProcessFinder;
+import org.apache.camel.dsl.jbang.core.common.ProcessFinder.CamelProcess;
+import org.apache.camel.dsl.jbang.run.common.LogFileReader;
+import org.apache.camel.util.StringHelper;
+import org.apache.camel.util.TimeUtils;
+import org.apache.camel.util.UnitUtils;
+import org.apache.camel.util.json.JsonArray;
+import org.apache.camel.util.json.JsonObject;
+
+/**
+ * The state of one running integration in one call (CAMEL-26941): what an 
agent otherwise asks with camel get route,
+ * get health, get error and log, each a JVM of its own.
+ */
+@CommandDefinition(name = "status",
+                   description = "The state of a running Camel integration in 
one call: where it runs and its files,"
+                                 + " its routes, health, last errors and last 
reload, its JVM, and the end of its log",
+                   generateHelp = true,
+                   footer = {
+                           "Examples:",
+                           "  camel status",
+                           "  camel status myapp --json",
+                           "  camel status myapp --log-lines=50" })
+public class IntegrationStatus extends ProcessBaseCommand {
+
+    // how many records of the log are read for the last reload, also when 
fewer are shown
+    private static final int RELOAD_RECORDS = 200;
+
+    @Argument(description = "Name or pid of the running Camel integration 
(default: the only one running)")
+    String name = "*";
+
+    @Option(name = "json", hasValue = false,
+            description = "Output in JSON Format: one document, with the 
routes as camel get route has them, and the log"
+                          + " records newest first")
+    boolean jsonOutput;
+
+    @Option(name = "log-lines", description = "How many of the last log 
records to show", defaultValue = "20")
+    int logLines = 20;
+
+    @Option(name = "errors", description = "How many of the last errors to 
show", defaultValue = "5")
+    int errors = 5;
+
+    public IntegrationStatus(CamelJBangMain main) {
+        super(main);
+    }
+
+    @Override
+    public Integer doCall() throws Exception {
+        if (("*".equals(name) || name == null || name.isBlank()) && 
ProcessFinder.find("*").isEmpty()) {
+            throw CliException.notFound("No running Camel integrations");
+        }
+        CamelProcess process = ProcessFinder.requireOne(name == null || 
name.isBlank() ? "*" : name);

Review Comment:
   💡 **Dead-code null/blank checks + double `ProcessFinder` scan** (Finding 1 — 
still open)
   
   `name` is `"*"` by default (the `@Argument` default value). The `name == 
null || name.isBlank()` branches on lines 81 and 84 are therefore dead: picocli 
never sets the field to `null` or blank after the default is applied. They 
obscure intent and suggest `name` can be `null`, which it cannot.
   
   There is also a double scan: `ProcessFinder.find("*")` on line 81 and 
`ProcessFinder.requireOne(...)` on line 84 both scan the running processes for 
the same query on the default path.
   
   Suggested fix:
   
   ```suggestion
           if ("*".equals(name) && ProcessFinder.find("*").isEmpty()) {
               throw CliException.notFound("No running Camel integrations");
           }
           CamelProcess process = ProcessFinder.requireOne(name);
   ```



##########
docs/user-manual/modules/ROOT/pages/camel-jbang-managing.adoc:
##########
@@ -136,6 +136,27 @@ Use `--remote` to break down TOTAL into remote/total pairs.
 
 TIP: Use `camel get --watch` for continuous updates.
 
+=== The state of one integration in one call
+
+`camel status` shows one integration. First what is wrong, in a few words 
each: a route that is not started or has
+failed exchanges, a health check that is down, a failed reload, a heap that is 
nearly full (`Problems: none` when all
+is well). Then its state and uptime, the folder it was started from and its 
files (the files of its routes, and the
+properties files it loaded), the exchanges and the oldest inflight one with 
where it is now (when the inflight
+exchanges are listed, as in dev mode), each route with its counters, its file 
and line, and last error, the health
+checks that are down, the HTTP server with its endpoints and management 
endpoints, the last errors, the reloads of
+dev mode with the outcome of the last one, the Java version, heap, threads and 
garbage collections of its JVM, and the
+end of its log. It is what `camel get route`, `camel get health`, `camel get 
error` and `camel log` show, in one
+command, which is what an AI agent wants after it has run or changed an 
integration:
+
+[source,bash]
+----
+camel status cheese --json
+----
+
+With `--json` it prints one document: `problems` is an empty list when all is 
well, the routes have the fields of
+`camel get route --json`, `uptime` is in millis, and the log records are 
newest first. Without a name it shows the only integration that runs. 
`--log-lines` and

Review Comment:
   💡 **Long run-on paragraph — still open, and worse** (Finding 2)
   
   The paragraph is two massive sentences (combined 9+ clauses) that are hard 
to parse, especially for the AI-agent audience this feature targets. The new 
commit added a third sentence to line 157 that wraps mid-word in the source 
(`--log-lines` and\n`--errors`), which is a source-formatting bug.
   
   Suggested rewrite:
   
   ```suggestion
   `camel status [name]` shows one integration in one call. First, what is 
wrong: a route that is not started or has failed exchanges, a health check that 
is down, a failed reload, or a heap that is nearly full (`Problems: none` when 
all is well). Then: its state, uptime, and directory; the files of its routes 
and properties; the exchanges and oldest inflight; each route with its counters 
and last error; the health checks that are down; the HTTP server and its 
endpoints; the last errors; dev-mode reloads with the outcome of the last one; 
JVM data; and the end of its log.
   
   With `--json` it prints one document: `problems` is an empty list when all 
is well, the routes have the fields of `camel get route --json`, `uptime` is in 
millis, and the log records are newest first.
   Without a name it shows the only integration that runs. `--log-lines` and 
`--errors` set how many log records and errors to show (default: 20 and 5).
   ```



-- 
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