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


##########
dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/process/IntegrationStatus.java:
##########
@@ -0,0 +1,434 @@
+/*
+ * 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.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 process scan**
   
   `name` is initialized to `"*"` and picocli never sets it to `null` or blank, 
so `name == null || name.isBlank()` is unreachable. Additionally, 
`ProcessFinder.find("*")` on line 80 and `ProcessFinder.requireOne(...)` on 
line 83 perform two separate scans of running processes.
   
   If you want a distinct "no integrations at all" message, one scan suffices:
   
   ```suggestion
           List<?> all = ProcessFinder.find("*");
           if (all.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,24 @@ 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: its state and uptime, the folder it was 
started from and the files of its
+routes, the exchanges, each route with its counters, its file and line, and 
last error, the health checks that are
+down, the HTTP 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:

Review Comment:
   💡 **Long paragraph — consider splitting**
   
   Two very long sentences. Suggested split:
   
   ```suggestion
   `camel status` shows one integration: its state and uptime, the folder it 
was started from and the files of its
   routes, the exchanges, each route with its counters, its file and line, and 
last error, the health checks that are
   down, the HTTP 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.
   
   In one command it replaces `camel get route`, `camel get health`, `camel get 
error` and `camel log` —
   which is what an AI agent wants after it has run or changed an integration:
   ```



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