use of io.confluent.ksql.cli.console.table.Table in project ksql by confluentinc.
the class Console method printConnectorDescription.
private void printConnectorDescription(final ConnectorDescription description) {
final ConnectorStateInfo status = description.getStatus();
writer().println(String.format("%-20s : %s", "Name", status.name()));
writer().println(String.format("%-20s : %s", "Class", description.getConnectorClass()));
writer().println(String.format("%-20s : %s", "Type", description.getStatus().type()));
writer().println(String.format("%-20s : %s", "State", status.connector().state()));
writer().println(String.format("%-20s : %s", "WorkerId", status.connector().workerId()));
if (!ObjectUtils.defaultIfNull(status.connector().trace(), "").isEmpty()) {
writer().println(String.format("%-20s : %s", "Trace", status.connector().trace()));
}
if (!status.tasks().isEmpty()) {
writer().println();
final Table taskTable = new Table.Builder().withColumnHeaders(ImmutableList.of("Task ID", "State", "Error Trace")).withRows(status.tasks().stream().map(task -> ImmutableList.of(String.valueOf(task.id()), task.state(), ObjectUtils.defaultIfNull(task.trace(), "")))).build();
taskTable.print(this);
}
if (!description.getSources().isEmpty()) {
writer().println();
final Table sourceTable = new Table.Builder().withColumnHeaders("KSQL Source Name", "Kafka Topic", "Type").withRows(description.getSources().stream().map(source -> ImmutableList.of(source.getName(), source.getTopic(), source.getType()))).build();
sourceTable.print(this);
}
if (!description.getTopics().isEmpty()) {
writer().println();
final Table topicTable = new Table.Builder().withColumnHeaders("Related Topics").withRows(description.getTopics().stream().map(ImmutableList::of)).build();
topicTable.print(this);
}
}
use of io.confluent.ksql.cli.console.table.Table in project ksql by confluentinc.
the class Console method printStatistics.
private void printStatistics(final SourceDescription source) {
final List<QueryHostStat> statistics = source.getClusterStatistics();
final List<QueryHostStat> errors = source.getClusterErrorStats();
if (statistics.isEmpty() && errors.isEmpty()) {
writer().println(String.format("%n%-20s%n%s", "Local runtime statistics", "------------------------"));
writer().println(source.getStatistics());
writer().println(source.getErrorStats());
return;
}
final List<String> headers = ImmutableList.of("Host", "Metric", "Value", "Last Message");
final Stream<QueryHostStat> rows = Streams.concat(statistics.stream(), errors.stream());
writer().println(String.format("%n%-20s%n%s", "Runtime statistics by host", "-------------------------"));
final Table statsTable = new Table.Builder().withColumnHeaders(headers).withRows(rows.sorted(Comparator.comparing(QueryHostStat::host).thenComparing(Stat::name)).map((metric) -> {
final String hostCell = metric.host().toString();
final String formattedValue = String.format("%10.0f", metric.getValue());
return ImmutableList.of(hostCell, metric.name(), formattedValue, metric.timestamp());
})).build();
statsTable.print(this);
}
use of io.confluent.ksql.cli.console.table.Table in project ksql by confluentinc.
the class QueriesTableBuilderTest method shouldBuildQueriesTableWithNewlines.
@Test
public void shouldBuildQueriesTableWithNewlines() {
// Given:
final RunningQuery query = new RunningQuery("CREATE STREAM S2 AS SELECT *\nFROM S1\nEMIT CHANGES;", ImmutableSet.of("S2"), ImmutableSet.of("S2"), new QueryId("CSAS_S2_0"), queryStatusCount, KsqlConstants.KsqlQueryType.PERSISTENT);
// When:
final Table table = buildTableWithSingleQuery(query);
// Then:
assertThat(table.headers(), contains("Query ID", "Query Type", "Status", "Sink Name", "Sink Kafka Topic", "Query String"));
assertThat(table.rows(), hasSize(1));
assertThat(table.rows().get(0), contains("CSAS_S2_0", KsqlConstants.KsqlQueryType.PERSISTENT.toString(), STATUS, "S2", "S2", "CREATE STREAM S2 AS SELECT * FROM S1 EMIT CHANGES;"));
}
use of io.confluent.ksql.cli.console.table.Table in project ksql by confluentinc.
the class QueriesTableBuilderTest method shouldBuildQueriesTable.
@Test
public void shouldBuildQueriesTable() {
// Given:
final String exampleQuery = "select * from test_stream emit changes";
final RunningQuery query = new RunningQuery(exampleQuery, ImmutableSet.of("SINK"), ImmutableSet.of("SINK"), new QueryId("0"), queryStatusCount, KsqlConstants.KsqlQueryType.PUSH);
// When:
final Table table = buildTableWithSingleQuery(query);
// Then:
assertThat(table.headers(), contains("Query ID", "Query Type", "Status", "Sink Name", "Sink Kafka Topic", "Query String"));
assertThat(table.rows(), hasSize(1));
assertThat(table.rows().get(0), contains("0", KsqlConstants.KsqlQueryType.PUSH.toString(), STATUS, "SINK", "SINK", exampleQuery));
}
use of io.confluent.ksql.cli.console.table.Table in project ksql by confluentinc.
the class PropertiesListTableBuilderTest method shouldHandlePropertiesWithNullValue.
@Test
public void shouldHandlePropertiesWithNullValue() {
// Given:
final PropertiesList propList = new PropertiesList("list properties;", Collections.singletonList(new Property(SOME_KEY, "KSQL", null)), Collections.emptyList(), ImmutableList.of(SOME_KEY));
// When:
final Table table = builder.buildTable(propList);
// Then:
assertThat(getRows(table), contains(row(SOME_KEY, "KSQL", "", "NULL")));
}
Aggregations