Search in sources :

Example 6 with RunningQuery

use of io.confluent.ksql.rest.entity.RunningQuery in project ksql by confluentinc.

the class ShowQueriesMultiNodeWithTlsFunctionalTest method getShowQueriesResult.

private static String getShowQueriesResult(final TestKsqlRestApp restApp) {
    final List<KsqlEntity> results = RestIntegrationTestUtil.makeKsqlRequest(restApp, "Show Queries;");
    if (results.size() != 1) {
        return "Expected 1 response, got " + results.size();
    }
    final KsqlEntity result = results.get(0);
    if (!(result instanceof Queries)) {
        return "Expected Queries, got " + result;
    }
    final List<RunningQuery> runningQueries = ((Queries) result).getQueries();
    if (runningQueries.size() != 1) {
        return "Expected 1 running query, got " + runningQueries.size();
    }
    return runningQueries.get(0).getStatusCount().toString();
}
Also used : Queries(io.confluent.ksql.rest.entity.Queries) RunningQuery(io.confluent.ksql.rest.entity.RunningQuery) KsqlEntity(io.confluent.ksql.rest.entity.KsqlEntity)

Example 7 with RunningQuery

use of io.confluent.ksql.rest.entity.RunningQuery in project ksql by confluentinc.

the class ConsoleTest method shouldPrintTopicDescribeExtended.

@Test
public void shouldPrintTopicDescribeExtended() {
    // Given:
    final List<RunningQuery> readQueries = ImmutableList.of(new RunningQuery("read query", ImmutableSet.of("sink1"), ImmutableSet.of("sink1 topic"), new QueryId("readId"), queryStatusCount, KsqlConstants.KsqlQueryType.PERSISTENT));
    final List<RunningQuery> writeQueries = ImmutableList.of(new RunningQuery("write query", ImmutableSet.of("sink2"), ImmutableSet.of("sink2 topic"), new QueryId("writeId"), queryStatusCount, KsqlConstants.KsqlQueryType.PERSISTENT));
    final KsqlEntityList entityList = new KsqlEntityList(ImmutableList.of(new SourceDescriptionEntity("e", new SourceDescription("TestSource", Optional.empty(), readQueries, writeQueries, buildTestSchema(SqlTypes.STRING), DataSourceType.KTABLE.getKsqlType(), "2000-01-01", "stats", "errors", true, "json", "avro", "kafka-topic", 2, 1, "sql statement text", ImmutableList.of(new QueryOffsetSummary("consumer1", ImmutableList.of(new QueryTopicOffsetSummary("kafka-topic", ImmutableList.of(new ConsumerPartitionOffsets(0, 100, 900, 800), new ConsumerPartitionOffsets(1, 50, 900, 900))), new QueryTopicOffsetSummary("kafka-topic-2", ImmutableList.of(new ConsumerPartitionOffsets(0, 0, 90, 80), new ConsumerPartitionOffsets(1, 10, 90, 90))))), new QueryOffsetSummary("consumer2", ImmutableList.of())), ImmutableList.of("S1", "S2")), Collections.emptyList())));
    // When:
    console.printKsqlEntityList(entityList);
    // Then:
    final String output = terminal.getOutputString();
    Approvals.verify(output, approvalOptions);
}
Also used : KsqlEntityList(io.confluent.ksql.rest.entity.KsqlEntityList) RunningQuery(io.confluent.ksql.rest.entity.RunningQuery) ConsumerPartitionOffsets(io.confluent.ksql.rest.entity.ConsumerPartitionOffsets) QueryId(io.confluent.ksql.query.QueryId) QueryOffsetSummary(io.confluent.ksql.rest.entity.QueryOffsetSummary) SourceDescriptionEntity(io.confluent.ksql.rest.entity.SourceDescriptionEntity) QueryTopicOffsetSummary(io.confluent.ksql.rest.entity.QueryTopicOffsetSummary) Matchers.containsString(org.hamcrest.Matchers.containsString) SourceDescription(io.confluent.ksql.rest.entity.SourceDescription) Test(org.junit.Test)

Example 8 with RunningQuery

use of io.confluent.ksql.rest.entity.RunningQuery in project ksql by confluentinc.

the class ConsoleTest method buildSourceDescription.

private SourceDescription buildSourceDescription(final List<RunningQuery> readQueries, final List<RunningQuery> writeQueries, final List<FieldInfo> fields, final boolean withClusterStats) {
    final Stat STAT = new Stat("TEST", 0, 1596644936314L);
    final Stat ERROR_STAT = new Stat("ERROR", 0, 1596644936314L);
    List<QueryHostStat> statistics = IntStream.range(1, 5).boxed().map((i) -> new KsqlHostInfoEntity("host" + i, 8000 + i)).map((host) -> QueryHostStat.fromStat(STAT, host)).collect(Collectors.toList());
    List<QueryHostStat> errors = IntStream.range(1, 5).boxed().map((i) -> new KsqlHostInfoEntity("host" + i, 8000 + i)).map((host) -> QueryHostStat.fromStat(ERROR_STAT, host)).collect(Collectors.toList());
    return new SourceDescription("TestSource", Optional.empty(), readQueries, writeQueries, fields, DataSourceType.KTABLE.getKsqlType(), "2000-01-01", "stats", "errors", true, "kafka", "avro", "kafka-topic", 1, 1, "sql statement", Collections.emptyList(), Collections.emptyList(), withClusterStats ? statistics : ImmutableList.of(), withClusterStats ? errors : ImmutableList.of());
}
Also used : StreamsList(io.confluent.ksql.rest.entity.StreamsList) ColumnName(io.confluent.ksql.name.ColumnName) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) RunningQuery(io.confluent.ksql.rest.entity.RunningQuery) SimpleConnectorPluginInfo(io.confluent.ksql.rest.entity.SimpleConnectorPluginInfo) KsqlQueryType(io.confluent.ksql.util.KsqlConstants.KsqlQueryType) SourceDescription(io.confluent.ksql.rest.entity.SourceDescription) StringUtils(org.apache.commons.lang3.StringUtils) Type(io.confluent.ksql.query.QueryError.Type) QueryHostStat(io.confluent.ksql.rest.entity.QueryHostStat) MockitoAnnotations(org.mockito.MockitoAnnotations) SchemaInfo(io.confluent.ksql.rest.entity.SchemaInfo) ConnectorList(io.confluent.ksql.rest.entity.ConnectorList) QueryId(io.confluent.ksql.query.QueryId) ConnectorType(org.apache.kafka.connect.runtime.rest.entities.ConnectorType) ClassRule(org.junit.ClassRule) CommandStatus(io.confluent.ksql.rest.entity.CommandStatus) SystemColumns(io.confluent.ksql.schema.ksql.SystemColumns) TypeList(io.confluent.ksql.rest.entity.TypeList) EnumMap(java.util.EnumMap) ConnectorState(org.apache.kafka.connect.runtime.rest.entities.ConnectorStateInfo.ConnectorState) ArgumentInfo(io.confluent.ksql.rest.entity.ArgumentInfo) Builder(io.confluent.ksql.schema.ksql.LogicalSchema.Builder) QueryDescription(io.confluent.ksql.rest.entity.QueryDescription) TopicDescription(io.confluent.ksql.rest.entity.TopicDescription) Matchers.is(org.hamcrest.Matchers.is) Matchers.containsString(org.hamcrest.Matchers.containsString) Mockito.mock(org.mockito.Mockito.mock) TimezoneRule(io.confluent.ksql.test.util.TimezoneRule) DropConnectorEntity(io.confluent.ksql.rest.entity.DropConnectorEntity) StreamedRow(io.confluent.ksql.rest.entity.StreamedRow) FieldInfo(io.confluent.ksql.rest.entity.FieldInfo) FunctionDescriptionList(io.confluent.ksql.rest.entity.FunctionDescriptionList) Mock(org.mockito.Mock) RunWith(org.junit.runner.RunWith) Stat(io.confluent.ksql.metrics.TopicSensors.Stat) Supplier(java.util.function.Supplier) SqlBaseType(io.confluent.ksql.schema.ksql.types.SqlBaseType) ArrayList(java.util.ArrayList) Strings(com.google.common.base.Strings) QueryStatusCount(io.confluent.ksql.rest.entity.QueryStatusCount) StreamsTaskMetadata(io.confluent.ksql.rest.entity.StreamsTaskMetadata) NoOpRowCaptor(io.confluent.ksql.cli.console.Console.NoOpRowCaptor) FakeException(io.confluent.ksql.FakeException) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) CliSpecificCommand(io.confluent.ksql.cli.console.cmd.CliSpecificCommand) SqlType(io.confluent.ksql.schema.ksql.types.SqlType) Before(org.junit.Before) IOException(java.io.IOException) Test(org.junit.Test) Mockito.never(org.mockito.Mockito.never) ConsumerPartitionOffsets(io.confluent.ksql.rest.entity.ConsumerPartitionOffsets) SqlTypes(io.confluent.ksql.schema.ksql.types.SqlTypes) KsqlWarning(io.confluent.ksql.rest.entity.KsqlWarning) ErrorEntity(io.confluent.ksql.rest.entity.ErrorEntity) ConnectorPluginsList(io.confluent.ksql.rest.entity.ConnectorPluginsList) QueryOffsetSummary(io.confluent.ksql.rest.entity.QueryOffsetSummary) TestTerminal(io.confluent.ksql.TestTerminal) TaskState(org.apache.kafka.connect.runtime.rest.entities.ConnectorStateInfo.TaskState) QueryTopicOffsetSummary(io.confluent.ksql.rest.entity.QueryTopicOffsetSummary) CommandId(io.confluent.ksql.rest.entity.CommandId) GenericRow.genericRow(io.confluent.ksql.GenericRow.genericRow) KsqlHostInfoEntity(io.confluent.ksql.rest.entity.KsqlHostInfoEntity) Approvals(org.approvaltests.Approvals) After(org.junit.After) ExecutionPlan(io.confluent.ksql.rest.entity.ExecutionPlan) EntityUtil(io.confluent.ksql.rest.util.EntityUtil) Parameterized(org.junit.runners.Parameterized) ImmutableSet(com.google.common.collect.ImmutableSet) PropertiesList(io.confluent.ksql.rest.entity.PropertiesList) ImmutableMap(com.google.common.collect.ImmutableMap) Errors(io.confluent.ksql.rest.Errors) TimeZone(java.util.TimeZone) Collection(java.util.Collection) LogicalSchema(io.confluent.ksql.schema.ksql.LogicalSchema) KsqlQueryStatus(io.confluent.ksql.util.KsqlConstants.KsqlQueryStatus) Collectors(java.util.stream.Collectors) ConnectorStateInfo(org.apache.kafka.connect.runtime.rest.entities.ConnectorStateInfo) List(java.util.List) FunctionInfo(io.confluent.ksql.rest.entity.FunctionInfo) ConnectorDescription(io.confluent.ksql.rest.entity.ConnectorDescription) Options(org.approvaltests.core.Options) Optional(java.util.Optional) KsqlConstants(io.confluent.ksql.util.KsqlConstants) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) IntStream(java.util.stream.IntStream) TerminateQueryEntity(io.confluent.ksql.rest.entity.TerminateQueryEntity) QueryDescriptionEntity(io.confluent.ksql.rest.entity.QueryDescriptionEntity) KsqlEntityList(io.confluent.ksql.rest.entity.KsqlEntityList) SimpleConnectorInfo(io.confluent.ksql.rest.entity.SimpleConnectorInfo) DataSourceType(io.confluent.ksql.metastore.model.DataSource.DataSourceType) QueryError(io.confluent.ksql.query.QueryError) KsqlEntity(io.confluent.ksql.rest.entity.KsqlEntity) FunctionType(io.confluent.ksql.rest.entity.FunctionType) ImmutableList(com.google.common.collect.ImmutableList) SourceDescriptionEntity(io.confluent.ksql.rest.entity.SourceDescriptionEntity) Queries(io.confluent.ksql.rest.entity.Queries) TablesList(io.confluent.ksql.rest.entity.TablesList) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) CommandStatusEntity(io.confluent.ksql.rest.entity.CommandStatusEntity) Mockito.when(org.mockito.Mockito.when) Property(io.confluent.ksql.rest.entity.PropertiesList.Property) Mockito.verify(org.mockito.Mockito.verify) SourceInfo(io.confluent.ksql.rest.entity.SourceInfo) Collections(java.util.Collections) QueryHostStat(io.confluent.ksql.rest.entity.QueryHostStat) Stat(io.confluent.ksql.metrics.TopicSensors.Stat) QueryHostStat(io.confluent.ksql.rest.entity.QueryHostStat) KsqlHostInfoEntity(io.confluent.ksql.rest.entity.KsqlHostInfoEntity) SourceDescription(io.confluent.ksql.rest.entity.SourceDescription)

Example 9 with RunningQuery

use of io.confluent.ksql.rest.entity.RunningQuery in project ksql by confluentinc.

the class ConsoleTest method testPrintSourceDescriptionWithExtractedHeader.

@Test
public void testPrintSourceDescriptionWithExtractedHeader() {
    // Given:
    final List<FieldInfo> fields = buildTestSchema(Optional.of("abc"), SqlTypes.BOOLEAN, SqlTypes.INTEGER, SqlTypes.BIGINT, SqlTypes.DOUBLE, SqlTypes.STRING, SqlTypes.array(SqlTypes.STRING), SqlTypes.map(SqlTypes.STRING, SqlTypes.BIGINT), SqlTypes.struct().field("a", SqlTypes.DOUBLE).build());
    final List<RunningQuery> readQueries = ImmutableList.of(new RunningQuery("read query", ImmutableSet.of("sink1"), ImmutableSet.of("sink1 topic"), new QueryId("readId"), queryStatusCount, KsqlConstants.KsqlQueryType.PERSISTENT));
    final List<RunningQuery> writeQueries = ImmutableList.of(new RunningQuery("write query", ImmutableSet.of("sink2"), ImmutableSet.of("sink2 topic"), new QueryId("writeId"), queryStatusCount, KsqlConstants.KsqlQueryType.PERSISTENT));
    final KsqlEntityList entityList = new KsqlEntityList(ImmutableList.of(new SourceDescriptionEntity("some sql", buildSourceDescription(readQueries, writeQueries, fields, false), Collections.emptyList())));
    // When:
    console.printKsqlEntityList(entityList);
    // Then:
    final String output = terminal.getOutputString();
    Approvals.verify(output, approvalOptions);
}
Also used : KsqlEntityList(io.confluent.ksql.rest.entity.KsqlEntityList) RunningQuery(io.confluent.ksql.rest.entity.RunningQuery) QueryId(io.confluent.ksql.query.QueryId) SourceDescriptionEntity(io.confluent.ksql.rest.entity.SourceDescriptionEntity) Matchers.containsString(org.hamcrest.Matchers.containsString) FieldInfo(io.confluent.ksql.rest.entity.FieldInfo) Test(org.junit.Test)

Example 10 with RunningQuery

use of io.confluent.ksql.rest.entity.RunningQuery in project ksql by confluentinc.

the class ConsoleTest method testPrintSourceDescriptionWithClusterStats.

@Test
public void testPrintSourceDescriptionWithClusterStats() {
    // Given:
    final List<FieldInfo> fields = buildTestSchema(SqlTypes.BOOLEAN, SqlTypes.INTEGER, SqlTypes.BIGINT, SqlTypes.DOUBLE, SqlTypes.STRING, SqlTypes.array(SqlTypes.STRING), SqlTypes.map(SqlTypes.STRING, SqlTypes.BIGINT), SqlTypes.struct().field("a", SqlTypes.DOUBLE).build());
    final List<RunningQuery> readQueries = ImmutableList.of(new RunningQuery("read query", ImmutableSet.of("sink1"), ImmutableSet.of("sink1 topic"), new QueryId("readId"), queryStatusCount, KsqlConstants.KsqlQueryType.PERSISTENT));
    final List<RunningQuery> writeQueries = ImmutableList.of(new RunningQuery("write query", ImmutableSet.of("sink2"), ImmutableSet.of("sink2 topic"), new QueryId("writeId"), queryStatusCount, KsqlConstants.KsqlQueryType.PERSISTENT));
    final KsqlEntityList entityList = new KsqlEntityList(ImmutableList.of(new SourceDescriptionEntity("some sql", buildSourceDescription(readQueries, writeQueries, fields, true), Collections.emptyList())));
    // When:
    console.printKsqlEntityList(entityList);
    // Then:
    final String output = terminal.getOutputString();
    Approvals.verify(output, approvalOptions);
}
Also used : KsqlEntityList(io.confluent.ksql.rest.entity.KsqlEntityList) RunningQuery(io.confluent.ksql.rest.entity.RunningQuery) QueryId(io.confluent.ksql.query.QueryId) SourceDescriptionEntity(io.confluent.ksql.rest.entity.SourceDescriptionEntity) Matchers.containsString(org.hamcrest.Matchers.containsString) FieldInfo(io.confluent.ksql.rest.entity.FieldInfo) Test(org.junit.Test)

Aggregations

RunningQuery (io.confluent.ksql.rest.entity.RunningQuery)25 QueryId (io.confluent.ksql.query.QueryId)16 Test (org.junit.Test)16 Queries (io.confluent.ksql.rest.entity.Queries)11 SourceDescriptionEntity (io.confluent.ksql.rest.entity.SourceDescriptionEntity)11 KsqlEntityList (io.confluent.ksql.rest.entity.KsqlEntityList)9 FieldInfo (io.confluent.ksql.rest.entity.FieldInfo)7 ArrayList (java.util.ArrayList)7 Matchers.containsString (org.hamcrest.Matchers.containsString)6 QueryOffsetSummary (io.confluent.ksql.rest.entity.QueryOffsetSummary)4 QueryStatusCount (io.confluent.ksql.rest.entity.QueryStatusCount)4 Map (java.util.Map)4 ImmutableMap (com.google.common.collect.ImmutableMap)3 BaseApiTest (io.confluent.ksql.api.BaseApiTest)3 MetricCollectors (io.confluent.ksql.metrics.MetricCollectors)3 CommandStatusEntity (io.confluent.ksql.rest.entity.CommandStatusEntity)3 KsqlEntity (io.confluent.ksql.rest.entity.KsqlEntity)3 PushQueryId (io.confluent.ksql.rest.entity.PushQueryId)3 QueryTopicOffsetSummary (io.confluent.ksql.rest.entity.QueryTopicOffsetSummary)3 SourceDescription (io.confluent.ksql.rest.entity.SourceDescription)3