Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,13 @@
* @return
*/
String serviceVersion() default "";

/**
* Whether this service supports a web UI (built-in or via companion container).
*
* When true, the service interface should provide a {@code uiUrl()} method that returns the UI URL when available.
*
* @return true if the service has UI support
*/
boolean uiSupported() default false;
}
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,9 @@ public int listServices(Consumer<List<Row>> serviceConsumer) throws IOException
if (service.aliasImplementation() != null) {
services.get(alias).getAliasImplementation().addAll(service.aliasImplementation());
}
if (service.uiSupported()) {
services.get(alias).setUiSupported(true);
}
}
}

Expand All @@ -182,7 +185,8 @@ public int listServices(Consumer<List<Row>> serviceConsumer) throws IOException
.sorted()
.collect(Collectors.joining(", ")),
entry.getValue().getDescription(),
getServiceData(entry.getKey(), pid)));
getServiceData(entry.getKey(), pid),
entry.getValue().isUiSupported()));
}

rows.sort(Comparator.comparing(InfraList.Row::alias));
Expand All @@ -195,7 +199,7 @@ public int listServices(Consumer<List<Row>> serviceConsumer) throws IOException
Jsoner.serialize(
rows.stream().map(row -> new InfraBaseDTO(
row.alias, row.aliasImplementation, row.description,
parseServiceData(row.serviceData())))
parseServiceData(row.serviceData()), row.uiSupported()))
.map(InfraBaseDTO::toMap)
.collect(Collectors.toList())));
} else {
Expand All @@ -204,19 +208,22 @@ public int listServices(Consumer<List<Row>> serviceConsumer) throws IOException
// IMPLEMENTATION is capped and SERVICE_DATA keeps a compact fixed width; both truncate with an ellipsis
// instead of overflowing the terminal (the full, structured service data is available via --json).
int serviceDataWidth = 30;
int uiWidth = 4;
int aliasWidth = width + 2;
int pidWidth = showPidColumn()
? CamelTableColumns.measure("PID", Integer.MAX_VALUE, rows, r -> r.pid) : 0;
int implWidth = CamelTableColumns.measure("IMPLEMENTATION", 35, rows, Row::aliasImplementation);
int overhead = TerminalWidthHelper.noBorderOverhead(showPidColumn() ? 5 : 4);
int overhead = TerminalWidthHelper.noBorderOverhead(showPidColumn() ? 6 : 5);
int descWidth = CamelTableColumns.lastColumnWidth(
tw, overhead, pidWidth, aliasWidth, implWidth, serviceDataWidth);
tw, overhead, pidWidth, aliasWidth, implWidth, uiWidth, serviceDataWidth);
printer().println(AsciiTable.getTable(AsciiTable.NO_BORDERS, rows, Arrays.asList(
new Column().header("PID").visible(showPidColumn()).headerAlign(HorizontalAlign.CENTER).with(r -> r.pid),
new Column().header("ALIAS").minWidth(aliasWidth).dataAlign(HorizontalAlign.LEFT)
.with(Row::alias),
new Column().header("IMPLEMENTATION").maxWidth(implWidth, OverflowBehaviour.ELLIPSIS_RIGHT)
.dataAlign(HorizontalAlign.LEFT).with(Row::aliasImplementation),
new Column().header("UI").maxWidth(uiWidth).dataAlign(HorizontalAlign.CENTER)
.with(r -> r.uiSupported() ? "x" : ""),
CamelTableColumns.lastText("DESCRIPTION", descWidth).with(Row::description),
new Column().header("SERVICE_DATA").maxWidth(serviceDataWidth, OverflowBehaviour.ELLIPSIS_RIGHT)
.dataAlign(HorizontalAlign.LEFT).with(Row::serviceData))));
Expand Down Expand Up @@ -286,15 +293,18 @@ record TestInfraService(
String groupId,
String artifactId,
String version,
String serviceVersion) {
String serviceVersion,
boolean uiSupported) {
}

record Row(String pid, String alias, String aliasImplementation, String description, String serviceData) {
record Row(String pid, String alias, String aliasImplementation, String description, String serviceData,
boolean uiSupported) {
}

private static class InfraServiceAlias {
private final String description;
private final Set<String> aliasImplementation = new HashSet<>();
private boolean uiSupported;

public InfraServiceAlias(String description) {
this.description = description;
Expand All @@ -307,5 +317,13 @@ public String getDescription() {
public Set<String> getAliasImplementation() {
return aliasImplementation;
}

public boolean isUiSupported() {
return uiSupported;
}

public void setUiSupported(boolean uiSupported) {
this.uiSupported = uiSupported;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@ protected Integer doRun(String testService, String testServiceImplementation, Te
if (port != null) {
System.setProperty("camel.infra.port", String.valueOf(port));
}

Object actualService = cl.loadClass(serviceImpl).newInstance();

// Make sure the actualService can be run with initialize method
Expand Down Expand Up @@ -364,4 +363,5 @@ public boolean isLogToStdout() {
public void setLogToStdout(boolean logToStdout) {
this.logToStdout = logToStdout;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,18 @@ public class InfraBaseDTO {
private String aliasImplementation;
private String description;
private Object serviceData;
private boolean uiSupported;

public InfraBaseDTO() {
}

public InfraBaseDTO(String alias, String aliasImplementation, String description, Object serviceData) {
public InfraBaseDTO(String alias, String aliasImplementation, String description, Object serviceData,
boolean uiSupported) {
this.alias = alias;
this.aliasImplementation = aliasImplementation;
this.description = description;
this.serviceData = serviceData;
this.uiSupported = uiSupported;
}

public String getAlias() {
Expand Down Expand Up @@ -69,6 +72,14 @@ public void setServiceData(Object serviceData) {
this.serviceData = serviceData;
}

public boolean isUiSupported() {
return uiSupported;
}

public void setUiSupported(boolean uiSupported) {
this.uiSupported = uiSupported;
}

public Map<String, Object> toMap() {
JsonObject jo = new JsonObject();
jo.put("alias", alias);
Expand All @@ -81,6 +92,7 @@ public Map<String, Object> toMap() {
if (serviceData != null) {
jo.put("serviceData", serviceData);
}
jo.put("uiSupported", uiSupported);
return jo;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public void serviceDataInJsonIsNestedNotEscaped() {
String rawServiceData = "{\"host\":\"localhost\",\"port\":61616}";
Object serviceData = InfraBaseCommand.parseServiceData(rawServiceData);

InfraBaseDTO dto = new InfraBaseDTO("artemis", "amqp", "AMQP broker", serviceData);
InfraBaseDTO dto = new InfraBaseDTO("artemis", "amqp", "AMQP broker", serviceData, true);
String json = Jsoner.serialize(List.of(dto.toMap()));

// serviceData is embedded as a nested JSON object (so --json is machine-parseable), not a string-escaped blob
Expand All @@ -93,7 +93,7 @@ public void malformedServiceDataIsOmittedFromJson() {
// unparseable content is dropped rather than emitted as an escaped string
Assertions.assertThat(serviceData).isNull();

InfraBaseDTO dto = new InfraBaseDTO("artemis", "amqp", "AMQP broker", serviceData);
InfraBaseDTO dto = new InfraBaseDTO("artemis", "amqp", "AMQP broker", serviceData, true);
String json = Jsoner.serialize(List.of(dto.toMap()));

Assertions.assertThat(json).contains("\"alias\":\"artemis\"");
Expand Down
Loading