Search in sources :

Example 6 with KsqlWarning

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

the class CommandTopicFunctionalTest method shouldReturnWarningsInRestResponseWhenDegradedCommandRunner.

@Test
public void shouldReturnWarningsInRestResponseWhenDegradedCommandRunner() {
    // When:
    REST_APP_1.start();
    RestIntegrationTestUtil.createStream(REST_APP_1, PAGE_VIEWS_PROVIDER);
    makeKsqlRequest(REST_APP_1, "CREATE STREAM S AS SELECT * FROM " + PAGE_VIEW_STREAM + ";" + "CREATE STREAM S2 AS SELECT * FROM S;");
    final List<KsqlEntity> results1 = makeKsqlRequest(REST_APP_1, "show streams; show topics; show tables;");
    results1.forEach(ksqlEntity -> {
        assertThat("Warning shouldn't be present in response", ksqlEntity.getWarnings().size() == 0);
    });
    HealthCheckResponse healthCheckResponse = RestIntegrationTestUtil.checkServerHealth(REST_APP_1);
    assertThat("CommandRunner healthcheck is healthy for server 1", healthCheckResponse.getDetails().get(COMMAND_RUNNER_CHECK_NAME).getIsHealthy());
    // Delete command topic while server 1 still running
    TEST_HARNESS.deleteTopics(Collections.singletonList(ReservedInternalTopics.commandTopic(new KsqlConfig(Collections.emptyMap()))));
    // Slight delay in warnings appearing since a consumer poll has to complete before CommandRunner becomes DEGRADED
    assertThatEventually("Corrupted warning should be present in response", () -> {
        final List<KsqlEntity> results2 = makeKsqlRequest(REST_APP_1, "show streams; show topics; show tables;");
        return results2.stream().allMatch(ksqlEntity -> {
            final List<KsqlWarning> warnings = ksqlEntity.getWarnings();
            return warnings.size() == 1 && warnings.get(0).getMessage().equals(DefaultErrorMessages.COMMAND_RUNNER_DEGRADED_CORRUPTED_ERROR_MESSAGE);
        });
    }, is(true));
    // need healthcheck cache to expire
    assertThatEventually("CommandRunner healthcheck is unhealthy for server 1", () -> {
        final HealthCheckResponse newHealthCheckResponse = RestIntegrationTestUtil.checkServerHealth(REST_APP_1);
        return newHealthCheckResponse.getDetails().get(COMMAND_RUNNER_CHECK_NAME).getIsHealthy();
    }, is(false));
    // Corrupted backup test
    REST_APP_2.start();
    // new DDL that diverges from backup triggers the corruption detection
    final List<KsqlEntity> results3 = makeKsqlRequest(REST_APP_2, "CREATE STREAM pageviews_divergent" + "(" + PAGE_VIEWS_PROVIDER.ksqlSchemaString(false) + ") " + "WITH (kafka_topic='" + PAGE_VIEWS_PROVIDER.topicName() + "', value_format='json');");
    results3.forEach(ksqlEntity -> {
        assertThat("Warning should be present in response", ksqlEntity.getWarnings().size() == 1);
        assertThat("Warning is corrupted warning", ksqlEntity.getWarnings().get(0).getMessage().equals(DefaultErrorMessages.COMMAND_RUNNER_DEGRADED_CORRUPTED_ERROR_MESSAGE));
    });
    assertThatEventually("CommandRunner healthcheck is unhealthy for server 2", () -> {
        final HealthCheckResponse newHealthCheckResponse = RestIntegrationTestUtil.checkServerHealth(REST_APP_2);
        return newHealthCheckResponse.getDetails().get(COMMAND_RUNNER_CHECK_NAME).getIsHealthy();
    }, is(false));
    // First server should still be in DEGRADED state even though second server created command topic on start up
    final List<KsqlEntity> results4 = makeKsqlRequest(REST_APP_1, "show streams;");
    results4.forEach(ksqlEntity -> {
        assertThat("Warning should be present in response", ksqlEntity.getWarnings().size() == 1);
        assertThat("Warning isn't corrupted warning", ksqlEntity.getWarnings().get(0).getMessage().equals(DefaultErrorMessages.COMMAND_RUNNER_DEGRADED_CORRUPTED_ERROR_MESSAGE));
    });
    healthCheckResponse = RestIntegrationTestUtil.checkServerHealth(REST_APP_1);
    assertThat("CommandRunner healthcheck is unhealthy for server 1", !healthCheckResponse.getDetails().get(COMMAND_RUNNER_CHECK_NAME).getIsHealthy());
}
Also used : HealthCheckResponse(io.confluent.ksql.rest.entity.HealthCheckResponse) KsqlConfig(io.confluent.ksql.util.KsqlConfig) KsqlWarning(io.confluent.ksql.rest.entity.KsqlWarning) KsqlEntity(io.confluent.ksql.rest.entity.KsqlEntity) IntegrationTest(io.confluent.common.utils.IntegrationTest) Test(org.junit.Test)

Example 7 with KsqlWarning

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

the class ListConnectorsExecutorTest method shouldListInvalidConnectorWithNoInfo.

@Test
public void shouldListInvalidConnectorWithNoInfo() {
    // Given:
    when(connectClient.connectors()).thenReturn(ConnectResponse.success(ImmutableList.of("connector2"), HttpStatus.SC_OK));
    final ConfiguredStatement<ListConnectors> statement = ConfiguredStatement.of(PreparedStatement.of("", new ListConnectors(Optional.empty(), Scope.ALL)), SessionConfig.of(new KsqlConfig(ImmutableMap.of()), ImmutableMap.of()));
    // When:
    final Optional<KsqlEntity> entity = EXECUTOR.execute(statement, mock(SessionProperties.class), engine, serviceContext).getEntity();
    // Then:
    assertThat("expected response!", entity.isPresent());
    final ConnectorList connectorList = (ConnectorList) entity.get();
    assertThat(connectorList, is(new ConnectorList("", ImmutableList.of(new KsqlWarning("Could not describe connector connector2: DANGER WILL ROBINSON.")), ImmutableList.of(new SimpleConnectorInfo("connector2", ConnectorType.UNKNOWN, null, null)))));
}
Also used : SimpleConnectorInfo(io.confluent.ksql.rest.entity.SimpleConnectorInfo) KsqlConfig(io.confluent.ksql.util.KsqlConfig) KsqlWarning(io.confluent.ksql.rest.entity.KsqlWarning) ConnectorList(io.confluent.ksql.rest.entity.ConnectorList) KsqlEntity(io.confluent.ksql.rest.entity.KsqlEntity) ListConnectors(io.confluent.ksql.parser.tree.ListConnectors) Test(org.junit.Test)

Example 8 with KsqlWarning

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

the class ListSourceExecutorTest method assertSourceListWithWarning.

private static void assertSourceListWithWarning(final KsqlEntity entity, final DataSource... sources) {
    assertThat(entity, instanceOf(SourceDescriptionList.class));
    final SourceDescriptionList listing = (SourceDescriptionList) entity;
    assertThat(listing.getSourceDescriptions(), containsInAnyOrder(Arrays.stream(sources).map(s -> equalTo(SourceDescriptionFactory.create(s, true, ImmutableList.of(), ImmutableList.of(), Optional.empty(), ImmutableList.of(), ImmutableList.of(), new MetricCollectors()))).collect(Collectors.toList())));
    assertThat(listing.getWarnings(), containsInAnyOrder(Arrays.stream(sources).map(s -> equalTo(new KsqlWarning("Error from Kafka: unknown topic: " + s.getKafkaTopicName()))).collect(Collectors.toList())));
}
Also used : DataSource(io.confluent.ksql.metastore.model.DataSource) Arrays(java.util.Arrays) StreamsList(io.confluent.ksql.rest.entity.StreamsList) SessionProperties(io.confluent.ksql.rest.SessionProperties) SourceName(io.confluent.ksql.name.SourceName) RunningQuery(io.confluent.ksql.rest.entity.RunningQuery) DescribeTables(io.confluent.ksql.parser.tree.DescribeTables) ServiceContext(io.confluent.ksql.services.ServiceContext) ExecuteResult(io.confluent.ksql.KsqlExecutionContext.ExecuteResult) SourceDescriptionList(io.confluent.ksql.rest.entity.SourceDescriptionList) PersistentQueryMetadata(io.confluent.ksql.util.PersistentQueryMetadata) KsqlTable(io.confluent.ksql.metastore.model.KsqlTable) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) TemporaryEngine(io.confluent.ksql.rest.server.TemporaryEngine) ConfiguredStatement(io.confluent.ksql.statement.ConfiguredStatement) Collectors(java.util.stream.Collectors) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) TestServiceContext(io.confluent.ksql.services.TestServiceContext) Matchers.contains(org.hamcrest.Matchers.contains) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) Matchers.equalTo(org.hamcrest.Matchers.equalTo) Optional(java.util.Optional) Node(org.apache.kafka.common.Node) Matchers.containsString(org.hamcrest.Matchers.containsString) KsqlConstants(io.confluent.ksql.util.KsqlConstants) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) Mockito.mock(org.mockito.Mockito.mock) FormatOptions(io.confluent.ksql.schema.utils.FormatOptions) Mock(org.mockito.Mock) Assert.assertThrows(org.junit.Assert.assertThrows) RunWith(org.junit.runner.RunWith) DataSourceType(io.confluent.ksql.metastore.model.DataSource.DataSourceType) Mockito.spy(org.mockito.Mockito.spy) MetricCollectors(io.confluent.ksql.metrics.MetricCollectors) KafkaTopicClient(io.confluent.ksql.services.KafkaTopicClient) KsqlHostInfo(io.confluent.ksql.util.KsqlHostInfo) SessionConfig(io.confluent.ksql.config.SessionConfig) KsqlEntity(io.confluent.ksql.rest.entity.KsqlEntity) QueryStatusCount(io.confluent.ksql.rest.entity.QueryStatusCount) ImmutableList(com.google.common.collect.ImmutableList) SourceDescriptionEntity(io.confluent.ksql.rest.entity.SourceDescriptionEntity) ShowColumns(io.confluent.ksql.parser.tree.ShowColumns) DescribeStreams(io.confluent.ksql.parser.tree.DescribeStreams) TablesList(io.confluent.ksql.rest.entity.TablesList) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) TopicDescription(org.apache.kafka.clients.admin.TopicDescription) ListTables(io.confluent.ksql.parser.tree.ListTables) Before(org.junit.Before) TopicPartitionInfo(org.apache.kafka.common.TopicPartitionInfo) ListStreams(io.confluent.ksql.parser.tree.ListStreams) EasyRandom(org.jeasy.random.EasyRandom) SourceDescriptionFactory(io.confluent.ksql.rest.entity.SourceDescriptionFactory) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) KsqlStream(io.confluent.ksql.metastore.model.KsqlStream) Mockito.verify(org.mockito.Mockito.verify) SourceInfo(io.confluent.ksql.rest.entity.SourceInfo) KsqlStatementException(io.confluent.ksql.util.KsqlStatementException) Mockito.never(org.mockito.Mockito.never) Rule(org.junit.Rule) Collections(java.util.Collections) PreparedStatement(io.confluent.ksql.parser.KsqlParser.PreparedStatement) KsqlWarning(io.confluent.ksql.rest.entity.KsqlWarning) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) SourceDescriptionList(io.confluent.ksql.rest.entity.SourceDescriptionList) MetricCollectors(io.confluent.ksql.metrics.MetricCollectors) KsqlWarning(io.confluent.ksql.rest.entity.KsqlWarning)

Example 9 with KsqlWarning

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

the class ConsoleTest method shouldPrintWarnings.

@Test
public void shouldPrintWarnings() {
    // Given:
    final KsqlEntity entity = new SourceDescriptionEntity("e", sourceDescription, ImmutableList.of(new KsqlWarning("oops"), new KsqlWarning("doh!")));
    // When:
    console.printKsqlEntityList(ImmutableList.of(entity));
    // Then:
    final String output = terminal.getOutputString();
    Approvals.verify(output, approvalOptions);
}
Also used : SourceDescriptionEntity(io.confluent.ksql.rest.entity.SourceDescriptionEntity) KsqlWarning(io.confluent.ksql.rest.entity.KsqlWarning) Matchers.containsString(org.hamcrest.Matchers.containsString) KsqlEntity(io.confluent.ksql.rest.entity.KsqlEntity) Test(org.junit.Test)

Example 10 with KsqlWarning

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

the class StreamStreamJoinsDeprecationNoticesIntegrationTest method shouldReturnDeprecationWarningMessageOnDeprecatedStatements.

@Test
public void shouldReturnDeprecationWarningMessageOnDeprecatedStatements() {
    // When
    final KsqlEntity ksqlEntity = makeKsqlRequest(String.format("CREATE STREAM DEPRECATED_QUERY AS " + "SELECT * FROM %s AS l " + "LEFT JOIN %s AS r WITHIN 1 SECOND ON l.K->F1 = r.K->F1;", STREAM_DATA_PROVIDER_1.sourceName(), STREAM_DATA_PROVIDER_2.sourceName())).get(0);
    // Then
    final CommandStatusEntity commandStatusEntity = (CommandStatusEntity) ksqlEntity;
    final CommandStatus commandStatus = commandStatusEntity.getCommandStatus();
    assertThat(commandStatus.getStatus(), is(CommandStatus.Status.SUCCESS));
    assertThat(commandStatus.getMessage(), containsString("Created query with ID CSAS_DEPRECATED_QUERY_"));
    assertThat(commandStatusEntity.getWarnings(), contains(new KsqlWarning("DEPRECATION NOTICE: Stream-stream joins statements without a GRACE PERIOD " + "will not be accepted in a future ksqlDB version.\n" + "Please use the GRACE PERIOD clause as specified in " + "https://docs.ksqldb.io/en/latest/developer-guide/ksqldb-reference/" + "select-push-query/")));
}
Also used : KsqlWarning(io.confluent.ksql.rest.entity.KsqlWarning) CommandStatus(io.confluent.ksql.rest.entity.CommandStatus) KsqlEntity(io.confluent.ksql.rest.entity.KsqlEntity) CommandStatusEntity(io.confluent.ksql.rest.entity.CommandStatusEntity) IntegrationTest(io.confluent.common.utils.IntegrationTest) Test(org.junit.Test)

Aggregations

KsqlWarning (io.confluent.ksql.rest.entity.KsqlWarning)10 KsqlEntity (io.confluent.ksql.rest.entity.KsqlEntity)7 Test (org.junit.Test)5 SessionProperties (io.confluent.ksql.rest.SessionProperties)3 SourceDescriptionEntity (io.confluent.ksql.rest.entity.SourceDescriptionEntity)3 ServiceContext (io.confluent.ksql.services.ServiceContext)3 ImmutableList (com.google.common.collect.ImmutableList)2 IntegrationTest (io.confluent.common.utils.IntegrationTest)2 KsqlExecutionContext (io.confluent.ksql.KsqlExecutionContext)2 DataSource (io.confluent.ksql.metastore.model.DataSource)2 MetricCollectors (io.confluent.ksql.metrics.MetricCollectors)2 ListConnectors (io.confluent.ksql.parser.tree.ListConnectors)2 ShowColumns (io.confluent.ksql.parser.tree.ShowColumns)2 ConnectorList (io.confluent.ksql.rest.entity.ConnectorList)2 HealthCheckResponse (io.confluent.ksql.rest.entity.HealthCheckResponse)2 RunningQuery (io.confluent.ksql.rest.entity.RunningQuery)2 SimpleConnectorInfo (io.confluent.ksql.rest.entity.SimpleConnectorInfo)2 SourceDescriptionFactory (io.confluent.ksql.rest.entity.SourceDescriptionFactory)2 ConnectResponse (io.confluent.ksql.services.ConnectClient.ConnectResponse)2 ConfiguredStatement (io.confluent.ksql.statement.ConfiguredStatement)2