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 4a948bb4966 CAMEL-21777: Add description output in camel-jbang. And fix description in Java DSL 4a948bb4966 is described below commit 4a948bb4966c94891c532d3187f71517c44adcb0 Author: Claus Ibsen <claus.ib...@gmail.com> AuthorDate: Fri Feb 28 11:29:46 2025 +0100 CAMEL-21777: Add description output in camel-jbang. And fix description in Java DSL --- .../apache/camel/model/ProcessorDefinition.java | 78 ++++++++++++++++++++++ .../commands/process/CamelProcessorStatus.java | 25 ++++++- .../core/commands/process/CamelRouteStatus.java | 30 ++++++++- 3 files changed, 130 insertions(+), 3 deletions(-) diff --git a/core/camel-core-model/src/main/java/org/apache/camel/model/ProcessorDefinition.java b/core/camel-core-model/src/main/java/org/apache/camel/model/ProcessorDefinition.java index 6917ea436af..88be9b1717e 100644 --- a/core/camel-core-model/src/main/java/org/apache/camel/model/ProcessorDefinition.java +++ b/core/camel-core-model/src/main/java/org/apache/camel/model/ProcessorDefinition.java @@ -805,6 +805,84 @@ public abstract class ProcessorDefinition<Type extends ProcessorDefinition<Type> return asType(); } + /** + * Sets the description of this node. + * <p/> + * <b>Important:</b> If you want to set the description of the route, then you <b>must</b> use {@link #routeDescription(String)} + * instead. + * + * @param description the description + * @return the builder + */ + @Override + public Type description(String description) { + // special for choice otherwise + if (this instanceof ChoiceDefinition cbr) { + if (cbr.getOtherwise() != null) { + if (cbr.getOtherwise().getOutputs().isEmpty()) { + cbr.getOtherwise().description(description); + } else { + var last = cbr.getOtherwise().getOutputs().get(cbr.getOtherwise().getOutputs().size() - 1); + last.description(description); + } + } else if (!cbr.getWhenClauses().isEmpty()) { + var last = cbr.getWhenClauses().get(cbr.getWhenClauses().size() - 1); + if (last.getOutputs().isEmpty()) { + last.setDescription(description); + } else { + var p = last.getOutputs().get(last.getOutputs().size() - 1); + p.description(description); + } + } else { + cbr.setDescription(description); + } + return asType(); + } + + if (this instanceof OutputNode && getOutputs().isEmpty()) { + // set description on this + setDescription(description); + } else { + List<ProcessorDefinition<?>> outputs = null; + if (this instanceof NoOutputDefinition<Type>) { + // this does not accept output so it should be on the parent + if (getParent() != null) { + outputs = getParent().getOutputs(); + } + } else if (this instanceof OutputExpressionNode) { + outputs = getOutputs(); + } else if (this instanceof ExpressionNode) { + // this does not accept output so it should be on the parent + if (getParent() != null) { + outputs = getParent().getOutputs(); + } + } else { + outputs = getOutputs(); + } + + // set it on last output as this is what the user means to do + // for Block(s) with non empty getOutputs() the id probably refers + // to the last definition in the current Block + if (!blocks.isEmpty()) { + if (blocks.getLast() instanceof ProcessorDefinition) { + ProcessorDefinition<?> block = (ProcessorDefinition<?>) blocks.getLast(); + if (!block.getOutputs().isEmpty()) { + outputs = block.getOutputs(); + } + } + } + if (outputs != null && !outputs.isEmpty()) { + // set description on last output + outputs.get(outputs.size() - 1).setDescription(description); + } else { + // the output could be empty + setDescription(description); + } + } + + return asType(); + } + /** * Disables this EIP from the route during build time. Once an EIP has been disabled then it cannot be enabled later * at runtime. diff --git a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/process/CamelProcessorStatus.java b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/process/CamelProcessorStatus.java index 70a2e1913f4..d90b74834f8 100644 --- a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/process/CamelProcessorStatus.java +++ b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/process/CamelProcessorStatus.java @@ -71,6 +71,10 @@ public class CamelProcessorStatus extends ProcessWatchCommand { description = "Filter processors that must be slower than the given time (ms)") long mean; + @CommandLine.Option(names = { "--description" }, + description = "Include description in the ID column (if available)") + boolean description; + public CamelProcessorStatus(CamelJBangMain main) { super(main); } @@ -99,6 +103,7 @@ public class CamelProcessorStatus extends ProcessWatchCommand { } row.pid = Long.toString(ph.pid()); row.routeId = o.getString("routeId"); + row.description = o.getString("description"); row.nodePrefixId = o.getString("nodePrefixId"); row.processor = o.getString("from"); row.source = o.getString("source"); @@ -177,6 +182,7 @@ public class CamelProcessorStatus extends ProcessWatchCommand { row.processorId = o.getString("id"); row.nodePrefixId = o.getString("nodePrefixId"); row.processor = o.getString("processor"); + row.description = o.getString("description"); row.level = o.getIntegerOrDefault("level", 0); row.source = o.getString("source"); Map<String, ?> stats = o.getMap("statistics"); @@ -231,8 +237,12 @@ public class CamelProcessorStatus extends ProcessWatchCommand { new Column().header("PID").headerAlign(HorizontalAlign.CENTER).with(this::getPid), new Column().header("NAME").dataAlign(HorizontalAlign.LEFT).maxWidth(30, OverflowBehaviour.ELLIPSIS_RIGHT) .with(this::getName), - new Column().header("ID").dataAlign(HorizontalAlign.LEFT).maxWidth(40, OverflowBehaviour.ELLIPSIS_RIGHT) + new Column().header("ID").visible(!description).dataAlign(HorizontalAlign.LEFT) + .maxWidth(40, OverflowBehaviour.ELLIPSIS_RIGHT) .with(this::getId), + new Column().header("ID").visible(description).dataAlign(HorizontalAlign.LEFT) + .maxWidth(60, OverflowBehaviour.NEWLINE) + .with(this::getIdAndDescription), new Column().header("PROCESSOR").dataAlign(HorizontalAlign.LEFT).minWidth(25) .maxWidth(45, OverflowBehaviour.ELLIPSIS_RIGHT) .with(this::getProcessor), @@ -305,6 +315,18 @@ public class CamelProcessorStatus extends ProcessWatchCommand { return answer; } + protected String getIdAndDescription(Row r) { + String id = getId(r); + if (description && r.description != null) { + if (id != null) { + id = id + "\n " + r.description; + } else { + id = r.description; + } + } + return id; + } + protected String getPid(Row r) { if (r.processorId == null) { return r.pid; @@ -334,6 +356,7 @@ public class CamelProcessorStatus extends ProcessWatchCommand { String nodePrefixId; String processorId; String processor; + String description; int level; String source; String state; 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 b2250e87a5d..996940fa7ec 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 @@ -71,6 +71,10 @@ public class CamelRouteStatus extends ProcessWatchCommand { description = "Shows detailed information for routes that has error status") boolean error; + @CommandLine.Option(names = { "--description" }, + description = "Include description in the ID column (if available)") + boolean description; + public CamelRouteStatus(CamelJBangMain main) { super(main); } @@ -100,6 +104,7 @@ public class CamelRouteStatus extends ProcessWatchCommand { } row.pid = Long.toString(ph.pid()); row.routeId = o.getString("routeId"); + row.description = o.getString("description"); row.from = o.getString("from"); Boolean bool = o.getBoolean("remote"); if (bool != null) { @@ -212,8 +217,12 @@ public class CamelRouteStatus extends ProcessWatchCommand { new Column().header("PID").headerAlign(HorizontalAlign.CENTER).with(r -> r.pid), new Column().header("NAME").dataAlign(HorizontalAlign.LEFT).maxWidth(30, OverflowBehaviour.ELLIPSIS_RIGHT) .with(r -> r.name), - new Column().header("ID").dataAlign(HorizontalAlign.LEFT).maxWidth(20, OverflowBehaviour.ELLIPSIS_RIGHT) + new Column().header("ID").visible(!description).dataAlign(HorizontalAlign.LEFT) + .maxWidth(20, OverflowBehaviour.ELLIPSIS_RIGHT) .with(this::getId), + new Column().header("ID").visible(description).dataAlign(HorizontalAlign.LEFT) + .maxWidth(45, OverflowBehaviour.NEWLINE) + .with(this::getIdAndDescription), new Column().header("FROM").visible(!wideUri).dataAlign(HorizontalAlign.LEFT) .maxWidth(45, OverflowBehaviour.ELLIPSIS_RIGHT) .with(this::getFrom), @@ -244,8 +253,12 @@ public class CamelRouteStatus extends ProcessWatchCommand { new Column().header("PID").headerAlign(HorizontalAlign.CENTER).with(r -> r.pid), new Column().header("NAME").dataAlign(HorizontalAlign.LEFT).maxWidth(30, OverflowBehaviour.ELLIPSIS_RIGHT) .with(r -> r.name), - new Column().header("ID").dataAlign(HorizontalAlign.LEFT).maxWidth(20, OverflowBehaviour.ELLIPSIS_RIGHT) + new Column().header("ID").visible(!description).dataAlign(HorizontalAlign.LEFT) + .maxWidth(20, OverflowBehaviour.ELLIPSIS_RIGHT) .with(this::getId), + new Column().header("ID").visible(description).dataAlign(HorizontalAlign.LEFT) + .maxWidth(45, OverflowBehaviour.NEWLINE) + .with(this::getIdAndDescription), new Column().header("FROM").visible(!wideUri).dataAlign(HorizontalAlign.LEFT) .maxWidth(45, OverflowBehaviour.ELLIPSIS_RIGHT) .with(this::getFrom), @@ -354,6 +367,18 @@ public class CamelRouteStatus extends ProcessWatchCommand { } } + protected String getIdAndDescription(Row r) { + String id = getId(r); + if (description && r.description != null) { + if (id != null) { + id = id + "\n " + r.description; + } else { + id = r.description; + } + } + return id; + } + protected String getDelta(Row r) { if (r.delta != null) { if (r.delta.startsWith("-")) { @@ -371,6 +396,7 @@ public class CamelRouteStatus extends ProcessWatchCommand { String name; long uptime; String routeId; + String description; String from; boolean remote; String source;