davsclaus commented on code in PR #29883: URL: https://github.com/apache/camel/pull/29883#discussion_r4569424886
########## 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: Fixed in e7d4ea2848d8: one scan. `ProcessFinder.find(query)` runs once, and the integration is taken from it when exactly one matches; `requireOne` runs only when none or several match, for its message. The null/blank guard stays, in one place: it is the same no-name rule as `ActionBaseCommand.findProcesses`, and costs nothing. _Claude Code on behalf of Claus Ibsen (davsclaus)_ ########## 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: Fixed in e7d4ea2848d8: one scan. `ProcessFinder.find(query)` runs once, and the integration is taken from it when exactly one matches; `requireOne` runs only when none or several match, for its message. The null/blank guard stays, in one place: it is the same no-name rule as `ActionBaseCommand.findProcesses`, and costs nothing. _Claude Code on behalf of Claus Ibsen (davsclaus)_ ########## 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: Split up in e7d4ea2848d8: one sentence on what the command is for, then what it starts with (the problems), then a list of what it shows, a lead-in to the example, and the default name and the `--log-lines` / `--errors` options in a paragraph of their own. The 163-column source line is gone. I used a list rather than the suggested semicolons, as it is easier to scan. _Claude Code on behalf of Claus Ibsen (davsclaus)_ ########## 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: Split up in e7d4ea2848d8: one sentence on what the command is for, then what it starts with (the problems), then a list of what it shows, a lead-in to the example, and the default name and the `--log-lines` / `--errors` options in a paragraph of their own. The 163-column source line is gone. I used a list rather than the suggested semicolons, as it is easier to scan. _Claude Code on behalf of Claus Ibsen (davsclaus)_ -- 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]
