Search in sources :

Example 1 with Table

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);
    }
}
Also used : Table(io.confluent.ksql.cli.console.table.Table) Builder(io.confluent.ksql.cli.console.table.Table.Builder) ImmutableList(com.google.common.collect.ImmutableList) ConnectorStateInfo(org.apache.kafka.connect.runtime.rest.entities.ConnectorStateInfo)

Example 2 with Table

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);
}
Also used : Table(io.confluent.ksql.cli.console.table.Table) Builder(io.confluent.ksql.cli.console.table.Table.Builder) QueryHostStat(io.confluent.ksql.rest.entity.QueryHostStat) Stat(io.confluent.ksql.metrics.TopicSensors.Stat) QueryHostStat(io.confluent.ksql.rest.entity.QueryHostStat)

Example 3 with Table

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;"));
}
Also used : RunningQuery(io.confluent.ksql.rest.entity.RunningQuery) Table(io.confluent.ksql.cli.console.table.Table) QueryId(io.confluent.ksql.query.QueryId) Test(org.junit.Test)

Example 4 with Table

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));
}
Also used : RunningQuery(io.confluent.ksql.rest.entity.RunningQuery) Table(io.confluent.ksql.cli.console.table.Table) QueryId(io.confluent.ksql.query.QueryId) Test(org.junit.Test)

Example 5 with Table

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")));
}
Also used : Table(io.confluent.ksql.cli.console.table.Table) PropertiesList(io.confluent.ksql.rest.entity.PropertiesList) Property(io.confluent.ksql.rest.entity.PropertiesList.Property) Test(org.junit.Test)

Aggregations

Table (io.confluent.ksql.cli.console.table.Table)9 Test (org.junit.Test)6 PropertiesList (io.confluent.ksql.rest.entity.PropertiesList)4 Property (io.confluent.ksql.rest.entity.PropertiesList.Property)4 Builder (io.confluent.ksql.cli.console.table.Table.Builder)3 QueryId (io.confluent.ksql.query.QueryId)2 RunningQuery (io.confluent.ksql.rest.entity.RunningQuery)2 ImmutableList (com.google.common.collect.ImmutableList)1 Stat (io.confluent.ksql.metrics.TopicSensors.Stat)1 QueryHostStat (io.confluent.ksql.rest.entity.QueryHostStat)1 QueryOffsetSummary (io.confluent.ksql.rest.entity.QueryOffsetSummary)1 QueryTopicOffsetSummary (io.confluent.ksql.rest.entity.QueryTopicOffsetSummary)1 ConnectorStateInfo (org.apache.kafka.connect.runtime.rest.entities.ConnectorStateInfo)1