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
The following commit(s) were added to refs/heads/main by this push:
new 6b9e8a97b1a CAMEL-18406: camel-jbang - Status command
6b9e8a97b1a is described below
commit 6b9e8a97b1af767137305613f5ca01d586ed9726
Author: Claus Ibsen <[email protected]>
AuthorDate: Wed Aug 24 07:35:59 2022 +0200
CAMEL-18406: camel-jbang - Status command
---
.../dsl/jbang/core/commands/CamelJBangMain.java | 4 +-
.../core/commands/process/CamelRouteStatus.java | 37 +++++++++++++++----
.../core/commands/process/CamelTopStatus.java | 43 ++++++++++++++++++++++
3 files changed, 76 insertions(+), 8 deletions(-)
diff --git
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/CamelJBangMain.java
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/CamelJBangMain.java
index 780d5a96d57..e19a4f0f55f 100644
---
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/CamelJBangMain.java
+++
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/CamelJBangMain.java
@@ -23,6 +23,7 @@ import org.apache.camel.catalog.DefaultCamelCatalog;
import org.apache.camel.dsl.jbang.core.commands.process.CamelContextStatus;
import org.apache.camel.dsl.jbang.core.commands.process.CamelRouteStatus;
import org.apache.camel.dsl.jbang.core.commands.process.CamelStatus;
+import org.apache.camel.dsl.jbang.core.commands.process.CamelTopStatus;
import org.apache.camel.dsl.jbang.core.commands.process.Hawtio;
import org.apache.camel.dsl.jbang.core.commands.process.Jolokia;
import org.apache.camel.dsl.jbang.core.commands.process.ListProcess;
@@ -43,7 +44,8 @@ public class CamelJBangMain implements Callable<Integer> {
.addSubcommand("stop", new CommandLine(new StopProcess(main)))
.addSubcommand("get", new CommandLine(new CamelStatus(main))
.addSubcommand("context", new CommandLine(new
CamelContextStatus(main)))
- .addSubcommand("route", new CommandLine(new
CamelRouteStatus(main))))
+ .addSubcommand("route", new CommandLine(new
CamelRouteStatus(main)))
+ .addSubcommand("top", new CommandLine(new
CamelTopStatus(main))))
.addSubcommand("generate", new CommandLine(new
CodeGenerator(main))
.addSubcommand("rest", new CommandLine(new
CodeRestGenerator(main))))
.addSubcommand("jolokia", new CommandLine(new Jolokia(main)))
diff --git
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/process/CamelRouteStatus.java
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/process/CamelRouteStatus.java
index 1c8f144c13f..ab21d2dfd69 100644
---
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/process/CamelRouteStatus.java
+++
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/process/CamelRouteStatus.java
@@ -46,6 +46,14 @@ public class CamelRouteStatus extends ProcessBaseCommand {
description = "Sort by pid, name or age", defaultValue
= "pid")
String sort;
+ @CommandLine.Option(names = { "--limit" },
+ description = "Filter routes by limiting to the given number of
rows")
+ int limit;
+
+ @CommandLine.Option(names = { "--filter-mean" },
+ description = "Filter routes that must be slower than
the given time (ms)")
+ long mean;
+
public CamelRouteStatus(CamelJBangMain main) {
super(main);
}
@@ -79,12 +87,8 @@ public class CamelRouteStatus extends ProcessBaseCommand {
for (int i = 0; i < array.size(); i++) {
JsonObject o = (JsonObject) array.get(i);
Row row = new Row();
- rows.add(row);
- if (i == 0) {
- // we only want pid/name in 1st row per
camel integration (to nest sub routes)
- row.pid = "" + ph.pid();
- row.name = name;
- }
+ row.pid = "" + ph.pid();
+ row.name = name;
row.routeId = o.getString("routeId");
row.from = o.getString("from");
row.source = o.getString("source");
@@ -106,11 +110,25 @@ public class CamelRouteStatus extends ProcessBaseCommand {
row.sinceLast = last.toString();
}
}
+
+ boolean add = true;
+ if (mean > 0 && row.mean != null &&
Long.parseLong(row.mean) < mean) {
+ add = false;
+ }
+ if (limit > 0 && rows.size() >= limit) {
+ add = false;
+ }
+ if (add) {
+ rows.add(row);
+ }
}
}
}
});
+ // sort rows
+ rows.sort(this::sortRow);
+
if (!rows.isEmpty()) {
System.out.println(AsciiTable.getTable(AsciiTable.BASIC_ASCII_NO_DATA_SEPARATORS,
rows, Arrays.asList(
new Column().header("PID").with(r -> r.pid),
@@ -151,7 +169,12 @@ public class CamelRouteStatus extends ProcessBaseCommand {
return null;
}
- private static class Row {
+ protected int sortRow(Row o1, Row o2) {
+ // no sort by default
+ return 0;
+ }
+
+ static class Row {
String pid;
String name;
String routeId;
diff --git
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/process/CamelTopStatus.java
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/process/CamelTopStatus.java
new file mode 100644
index 00000000000..44d6e8a17ea
--- /dev/null
+++
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/process/CamelTopStatus.java
@@ -0,0 +1,43 @@
+/*
+ * 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 org.apache.camel.dsl.jbang.core.commands.CamelJBangMain;
+import picocli.CommandLine.Command;
+
+@Command(name = "top", description = "Top performing routes")
+public class CamelTopStatus extends CamelRouteStatus {
+
+ public CamelTopStatus(CamelJBangMain main) {
+ super(main);
+ }
+
+ @Override
+ protected int sortRow(Row o1, Row o2) {
+ // sort for highest mean value as we want the slowest in the top
+ long m1 = o1.mean != null ? Long.parseLong(o1.mean) : 0;
+ long m2 = o2.mean != null ? Long.parseLong(o2.mean) : 0;
+ if (m1 < m2) {
+ return 1;
+ } else if (m1 > m2) {
+ return -1;
+ } else {
+ return 0;
+ }
+ }
+
+}