Search in sources :

Example 11 with KsqlHostInfoEntity

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

the class PullQueryRoutingFunctionalTest method shouldQueryStandbyWhenActiveDeadStandbyAliveQueryIssuedToRouter.

@Test
public void shouldQueryStandbyWhenActiveDeadStandbyAliveQueryIssuedToRouter() throws Exception {
    // Given:
    ClusterFormation clusterFormation = findClusterFormation(TEST_APP_0, TEST_APP_1, TEST_APP_2);
    waitForClusterToBeDiscovered(clusterFormation.router.getApp(), 3, USER_CREDS);
    waitForRemoteServerToChangeStatus(clusterFormation.router.getApp(), clusterFormation.router.getHost(), HighAvailabilityTestUtil.lagsReported(3), USER_CREDS);
    // Partition off the active
    clusterFormation.active.getShutoffs().shutOffAll();
    waitForRemoteServerToChangeStatus(clusterFormation.router.getApp(), clusterFormation.standBy.getHost(), HighAvailabilityTestUtil::remoteServerIsUp, USER_CREDS);
    waitForRemoteServerToChangeStatus(clusterFormation.router.getApp(), clusterFormation.active.getHost(), HighAvailabilityTestUtil::remoteServerIsDown, USER_CREDS);
    // When:
    final List<StreamedRow> rows_0 = makePullQueryRequest(clusterFormation.router.getApp(), sql, null, USER_CREDS);
    // Then:
    assertThat(rows_0, hasSize(HEADER + 1));
    KsqlHostInfoEntity host = rows_0.get(1).getSourceHost().get();
    assertThat(host.getHost(), is(clusterFormation.standBy.getHost().getHost()));
    assertThat(host.getPort(), is(clusterFormation.standBy.getHost().getPort()));
    assertThat(rows_0.get(1).getRow(), is(not(Optional.empty())));
    assertThat(rows_0.get(1).getRow().get().getColumns(), is(ImmutableList.of(KEY, 1)));
}
Also used : StreamedRow(io.confluent.ksql.rest.entity.StreamedRow) KsqlHostInfoEntity(io.confluent.ksql.rest.entity.KsqlHostInfoEntity) IntegrationTest(io.confluent.common.utils.IntegrationTest) Test(org.junit.Test)

Example 12 with KsqlHostInfoEntity

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

the class PullQueryRoutingFunctionalTest method shouldQueryStandbyWhenActiveDeadStandbyAliveQueryIssuedToRouter_multipleKeys.

@SuppressWarnings("unchecked")
@Test
public void shouldQueryStandbyWhenActiveDeadStandbyAliveQueryIssuedToRouter_multipleKeys() throws Exception {
    // Given:
    ClusterFormation clusterFormation = findClusterFormation(TEST_APP_0, TEST_APP_1, TEST_APP_2);
    waitForClusterToBeDiscovered(clusterFormation.router.getApp(), 3, USER_CREDS);
    waitForRemoteServerToChangeStatus(clusterFormation.router.getApp(), clusterFormation.router.getHost(), HighAvailabilityTestUtil.lagsReported(3), USER_CREDS);
    // Partition off the active
    clusterFormation.active.getShutoffs().shutOffAll();
    waitForRemoteServerToChangeStatus(clusterFormation.router.getApp(), clusterFormation.standBy.getHost(), HighAvailabilityTestUtil::remoteServerIsUp, USER_CREDS);
    waitForRemoteServerToChangeStatus(clusterFormation.router.getApp(), clusterFormation.active.getHost(), HighAvailabilityTestUtil::remoteServerIsDown, USER_CREDS);
    // When:
    final List<StreamedRow> rows_0 = makePullQueryRequest(clusterFormation.router.getApp(), sqlMultipleKeys, null, USER_CREDS);
    // Then:
    assertThat(rows_0, hasSize(HEADER + 2));
    KsqlHostInfoEntity host = rows_0.get(1).getSourceHost().get();
    assertThat(host.getHost(), is(clusterFormation.standBy.getHost().getHost()));
    assertThat(host.getPort(), is(clusterFormation.standBy.getHost().getPort()));
    host = rows_0.get(2).getSourceHost().get();
    assertThat(host.getHost(), is(clusterFormation.standBy.getHost().getHost()));
    assertThat(host.getPort(), is(clusterFormation.standBy.getHost().getPort()));
    List<List<?>> values = rows_0.stream().skip(HEADER).map(sr -> {
        assertThat(sr.getRow(), is(not(Optional.empty())));
        return sr.getRow().get().getColumns();
    }).collect(Collectors.toList());
    assertThat(values, containsInAnyOrder(ImmutableList.of(KEY, 1), ImmutableList.of(KEY1, 1)));
}
Also used : HighAvailabilityTestUtil.waitForRemoteServerToChangeStatus(io.confluent.ksql.rest.integration.HighAvailabilityTestUtil.waitForRemoteServerToChangeStatus) PhysicalSchema(io.confluent.ksql.schema.ksql.PhysicalSchema) HighAvailabilityTestUtil.makePullQueryRequest(io.confluent.ksql.rest.integration.HighAvailabilityTestUtil.makePullQueryRequest) ColumnName(io.confluent.ksql.name.ColumnName) Matchers.not(org.hamcrest.Matchers.not) LoggerFactory(org.slf4j.LoggerFactory) RoutingContext(io.vertx.ext.web.RoutingContext) ClusterStatusResponse(io.confluent.ksql.rest.entity.ClusterStatusResponse) KsqlErrorMessage(io.confluent.ksql.rest.entity.KsqlErrorMessage) WorkerExecutor(io.vertx.core.WorkerExecutor) KsqlHostInfoEntity(io.confluent.ksql.rest.entity.KsqlHostInfoEntity) HighAvailabilityTestUtil.makeAdminRequestWithResponse(io.confluent.ksql.rest.integration.HighAvailabilityTestUtil.makeAdminRequestWithResponse) Map(java.util.Map) After(org.junit.After) FaultyKafkaConsumer0(io.confluent.ksql.rest.integration.FaultyKafkaConsumer.FaultyKafkaConsumer0) FaultyKafkaConsumer2(io.confluent.ksql.rest.integration.FaultyKafkaConsumer.FaultyKafkaConsumer2) FaultyKafkaConsumer1(io.confluent.ksql.rest.integration.FaultyKafkaConsumer.FaultyKafkaConsumer1) ClassRule(org.junit.ClassRule) ZooKeeperClientException(kafka.zookeeper.ZooKeeperClientException) ImmutableMap(com.google.common.collect.ImmutableMap) TestKsqlRestApp(io.confluent.ksql.rest.server.TestKsqlRestApp) Set(java.util.Set) ConsumerConfig(org.apache.kafka.clients.consumer.ConsumerConfig) KsqlConfig(io.confluent.ksql.util.KsqlConfig) UUID(java.util.UUID) RecordMetadata(org.apache.kafka.clients.producer.RecordMetadata) Category(org.junit.experimental.categories.Category) LogicalSchema(io.confluent.ksql.schema.ksql.LogicalSchema) Collectors(java.util.stream.Collectors) KsqlRestConfig(io.confluent.ksql.rest.server.KsqlRestConfig) List(java.util.List) Principal(java.security.Principal) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) Entry(java.util.Map.Entry) Optional(java.util.Optional) Matchers.is(org.hamcrest.Matchers.is) UserDataProvider(io.confluent.ksql.util.UserDataProvider) HighAvailabilityTestUtil.makeAdminRequest(io.confluent.ksql.rest.integration.HighAvailabilityTestUtil.makeAdminRequest) Matchers.containsString(org.hamcrest.Matchers.containsString) Retry(io.confluent.ksql.integration.Retry) StreamsConfig(org.apache.kafka.streams.StreamsConfig) StreamedRow(io.confluent.ksql.rest.entity.StreamedRow) TaskId(org.apache.kafka.streams.processor.TaskId) BeforeClass(org.junit.BeforeClass) HighAvailabilityTestUtil.waitForStreamsMetadataToInitialize(io.confluent.ksql.rest.integration.HighAvailabilityTestUtil.waitForStreamsMetadataToInitialize) FormatFactory(io.confluent.ksql.serde.FormatFactory) AssignmentConfigs(org.apache.kafka.streams.processor.internals.assignment.AssignorConfiguration.AssignmentConfigs) CompletableFuture(java.util.concurrent.CompletableFuture) KsqlIdentifierTestUtil(io.confluent.ksql.test.util.KsqlIdentifierTestUtil) Multimap(com.google.common.collect.Multimap) HighAvailabilityTestUtil.extractQueryId(io.confluent.ksql.rest.integration.HighAvailabilityTestUtil.extractQueryId) KsqlEntity(io.confluent.ksql.rest.entity.KsqlEntity) ImmutableList(com.google.common.collect.ImmutableList) Shutoffs(io.confluent.ksql.rest.integration.HighAvailabilityTestUtil.Shutoffs) KsqlTestFolder(io.confluent.ksql.test.util.KsqlTestFolder) Timeout(org.junit.rules.Timeout) Matchers.hasSize(org.hamcrest.Matchers.hasSize) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) SerdeFeatures(io.confluent.ksql.serde.SerdeFeatures) Before(org.junit.Before) AuthenticationPlugin(io.confluent.ksql.api.auth.AuthenticationPlugin) Logger(org.slf4j.Logger) IntegrationTest(io.confluent.common.utils.IntegrationTest) HighAvailabilityTestUtil.waitForClusterToBeDiscovered(io.confluent.ksql.rest.integration.HighAvailabilityTestUtil.waitForClusterToBeDiscovered) CONSUMER_PREFIX(org.apache.kafka.streams.StreamsConfig.CONSUMER_PREFIX) KSQL_STREAMS_PREFIX(io.confluent.ksql.util.KsqlConfig.KSQL_STREAMS_PREFIX) TestUtils(io.confluent.ksql.rest.server.utils.TestUtils) BasicCredentials(io.confluent.ksql.rest.client.BasicCredentials) IOException(java.io.IOException) Test(org.junit.Test) IntegrationTestHarness(io.confluent.ksql.integration.IntegrationTestHarness) TestBasicJaasConfig(io.confluent.ksql.test.util.TestBasicJaasConfig) TimeUnit(java.util.concurrent.TimeUnit) RuleChain(org.junit.rules.RuleChain) ActiveStandbyEntity(io.confluent.ksql.rest.entity.ActiveStandbyEntity) AtomicLong(java.util.concurrent.atomic.AtomicLong) Rule(org.junit.Rule) ClientState(org.apache.kafka.streams.processor.internals.assignment.ClientState) TaskAssignor(org.apache.kafka.streams.processor.internals.assignment.TaskAssignor) Preconditions(com.google.common.base.Preconditions) GenericKey(io.confluent.ksql.GenericKey) Comparator(java.util.Comparator) Assert(org.junit.Assert) SqlTypes(io.confluent.ksql.schema.ksql.types.SqlTypes) TemporaryFolder(org.junit.rules.TemporaryFolder) StreamedRow(io.confluent.ksql.rest.entity.StreamedRow) KsqlHostInfoEntity(io.confluent.ksql.rest.entity.KsqlHostInfoEntity) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) IntegrationTest(io.confluent.common.utils.IntegrationTest) Test(org.junit.Test)

Example 13 with KsqlHostInfoEntity

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

the class HighAvailabilityTestUtil method getOffsets.

// Gets (current, end) offsets for the given host.  Makes the simplified assumption that there's
// just one state store.
public static Pair<Long, Long> getOffsets(final KsqlHostInfoEntity server, final Map<KsqlHostInfoEntity, HostStatusEntity> clusterStatus) {
    HostStatusEntity hostStatusEntity = clusterStatus.get(server);
    long end = hostStatusEntity.getHostStoreLags().getStateStoreLags().values().stream().flatMap(stateStoreLags -> stateStoreLags.getLagByPartition().values().stream()).mapToLong(LagInfoEntity::getEndOffsetPosition).max().orElse(0);
    long current = hostStatusEntity.getHostStoreLags().getStateStoreLags().values().stream().flatMap(stateStoreLags -> stateStoreLags.getLagByPartition().values().stream()).mapToLong(LagInfoEntity::getCurrentOffsetPosition).max().orElse(0);
    return Pair.of(current, end);
}
Also used : StreamedRow(io.confluent.ksql.rest.entity.StreamedRow) BiFunction(java.util.function.BiFunction) LoggerFactory(org.slf4j.LoggerFactory) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ClusterStatusResponse(io.confluent.ksql.rest.entity.ClusterStatusResponse) LagInfoEntity(io.confluent.ksql.rest.entity.LagInfoEntity) RestResponse(io.confluent.ksql.rest.client.RestResponse) HeartbeatResponse(io.confluent.ksql.rest.entity.HeartbeatResponse) Function(java.util.function.Function) KsqlEntity(io.confluent.ksql.rest.entity.KsqlEntity) KsqlHostInfoEntity(io.confluent.ksql.rest.entity.KsqlHostInfoEntity) KsqlRestClient(io.confluent.ksql.rest.client.KsqlRestClient) Pair(io.confluent.ksql.util.Pair) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) LagReportingMessage(io.confluent.ksql.rest.entity.LagReportingMessage) HostStatusEntity(io.confluent.ksql.rest.entity.HostStatusEntity) KsqlRequestConfig(io.confluent.ksql.util.KsqlRequestConfig) Logger(org.slf4j.Logger) ImmutableMap(com.google.common.collect.ImmutableMap) TestKsqlRestApp(io.confluent.ksql.rest.server.TestKsqlRestApp) BasicCredentials(io.confluent.ksql.rest.client.BasicCredentials) Collectors(java.util.stream.Collectors) ExecutionException(java.util.concurrent.ExecutionException) List(java.util.List) Entry(java.util.Map.Entry) Optional(java.util.Optional) Pattern(java.util.regex.Pattern) LagInfoEntity(io.confluent.ksql.rest.entity.LagInfoEntity) HostStatusEntity(io.confluent.ksql.rest.entity.HostStatusEntity)

Example 14 with KsqlHostInfoEntity

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

the class HighAvailabilityTestUtil method waitForStreamsMetadataToInitialize.

static void waitForStreamsMetadataToInitialize(final TestKsqlRestApp restApp, List<KsqlHostInfoEntity> hosts, final Optional<BasicCredentials> credentials) {
    while (true) {
        ClusterStatusResponse clusterStatusResponse = HighAvailabilityTestUtil.sendClusterStatusRequest(restApp, credentials);
        List<KsqlHostInfoEntity> initialized = hosts.stream().filter(hostInfo -> Optional.ofNullable(clusterStatusResponse.getClusterStatus().get(hostInfo)).map(hostStatusEntity -> hostStatusEntity.getActiveStandbyPerQuery().isEmpty()).isPresent()).collect(Collectors.toList());
        if (initialized.size() == hosts.size())
            break;
    }
    try {
        Thread.sleep(200);
    } catch (final Exception e) {
    // Meh
    }
}
Also used : StreamedRow(io.confluent.ksql.rest.entity.StreamedRow) BiFunction(java.util.function.BiFunction) LoggerFactory(org.slf4j.LoggerFactory) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ClusterStatusResponse(io.confluent.ksql.rest.entity.ClusterStatusResponse) LagInfoEntity(io.confluent.ksql.rest.entity.LagInfoEntity) RestResponse(io.confluent.ksql.rest.client.RestResponse) HeartbeatResponse(io.confluent.ksql.rest.entity.HeartbeatResponse) Function(java.util.function.Function) KsqlEntity(io.confluent.ksql.rest.entity.KsqlEntity) KsqlHostInfoEntity(io.confluent.ksql.rest.entity.KsqlHostInfoEntity) KsqlRestClient(io.confluent.ksql.rest.client.KsqlRestClient) Pair(io.confluent.ksql.util.Pair) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) LagReportingMessage(io.confluent.ksql.rest.entity.LagReportingMessage) HostStatusEntity(io.confluent.ksql.rest.entity.HostStatusEntity) KsqlRequestConfig(io.confluent.ksql.util.KsqlRequestConfig) Logger(org.slf4j.Logger) ImmutableMap(com.google.common.collect.ImmutableMap) TestKsqlRestApp(io.confluent.ksql.rest.server.TestKsqlRestApp) BasicCredentials(io.confluent.ksql.rest.client.BasicCredentials) Collectors(java.util.stream.Collectors) ExecutionException(java.util.concurrent.ExecutionException) List(java.util.List) Entry(java.util.Map.Entry) Optional(java.util.Optional) Pattern(java.util.regex.Pattern) ClusterStatusResponse(io.confluent.ksql.rest.entity.ClusterStatusResponse) KsqlHostInfoEntity(io.confluent.ksql.rest.entity.KsqlHostInfoEntity) ExecutionException(java.util.concurrent.ExecutionException)

Example 15 with KsqlHostInfoEntity

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

the class ListQueriesExecutorTest method shouldIncludeUnresponsiveIfShowQueriesExtendedFutureThrowsException.

@Test
public void shouldIncludeUnresponsiveIfShowQueriesExtendedFutureThrowsException() {
    // Given
    when(sessionProperties.getInternalRequest()).thenReturn(false);
    final ConfiguredStatement<ListQueries> showQueries = (ConfiguredStatement<ListQueries>) engine.configure("SHOW QUERIES EXTENDED;");
    final PersistentQueryMetadata metadata = givenPersistentQuery("id", RUNNING_QUERY_STATE);
    final KsqlEngine engine = mock(KsqlEngine.class);
    when(engine.getAllLiveQueries()).thenReturn(ImmutableList.of(metadata));
    when(engine.getPersistentQueries()).thenReturn(ImmutableList.of(metadata));
    when(ksqlClient.makeKsqlRequest(any(), any(), any())).thenThrow(new KsqlRestClientException("error"));
    when(serviceContext.getKsqlClient()).thenReturn(ksqlClient);
    // When
    final Map<KsqlHostInfoEntity, KsqlQueryStatus> map = new HashMap<>();
    map.put(LOCAL_KSQL_HOST_INFO_ENTITY, KsqlQueryStatus.RUNNING);
    map.put(REMOTE_KSQL_HOST_INFO_ENTITY, KsqlQueryStatus.UNRESPONSIVE);
    // When
    final QueryDescriptionList queries = (QueryDescriptionList) CUSTOM_EXECUTORS.listQueries().execute(showQueries, sessionProperties, engine, serviceContext).getEntity().orElseThrow(IllegalStateException::new);
    // Then
    assertThat(queries.getQueryDescriptions(), containsInAnyOrder(QueryDescriptionFactory.forQueryMetadata(metadata, map)));
}
Also used : ConfiguredStatement(io.confluent.ksql.statement.ConfiguredStatement) KsqlEngine(io.confluent.ksql.engine.KsqlEngine) KsqlRestClientException(io.confluent.ksql.rest.client.exception.KsqlRestClientException) HashMap(java.util.HashMap) ListQueries(io.confluent.ksql.parser.tree.ListQueries) QueryDescriptionList(io.confluent.ksql.rest.entity.QueryDescriptionList) KsqlHostInfoEntity(io.confluent.ksql.rest.entity.KsqlHostInfoEntity) PersistentQueryMetadata(io.confluent.ksql.util.PersistentQueryMetadata) KsqlQueryStatus(io.confluent.ksql.util.KsqlConstants.KsqlQueryStatus) Test(org.junit.Test)

Aggregations

KsqlHostInfoEntity (io.confluent.ksql.rest.entity.KsqlHostInfoEntity)23 Test (org.junit.Test)17 StreamedRow (io.confluent.ksql.rest.entity.StreamedRow)9 PersistentQueryMetadata (io.confluent.ksql.util.PersistentQueryMetadata)7 IntegrationTest (io.confluent.common.utils.IntegrationTest)6 KsqlEngine (io.confluent.ksql.engine.KsqlEngine)6 QueryDescriptionList (io.confluent.ksql.rest.entity.QueryDescriptionList)6 KsqlQueryStatus (io.confluent.ksql.util.KsqlConstants.KsqlQueryStatus)6 ImmutableMap (com.google.common.collect.ImmutableMap)5 QueryDescription (io.confluent.ksql.rest.entity.QueryDescription)5 ConfiguredStatement (io.confluent.ksql.statement.ConfiguredStatement)5 Map (java.util.Map)5 Optional (java.util.Optional)5 ListQueries (io.confluent.ksql.parser.tree.ListQueries)4 ClusterStatusResponse (io.confluent.ksql.rest.entity.ClusterStatusResponse)4 HeartbeatResponse (io.confluent.ksql.rest.entity.HeartbeatResponse)4 KsqlEntity (io.confluent.ksql.rest.entity.KsqlEntity)4 List (java.util.List)4 Collectors (java.util.stream.Collectors)4 ImmutableList (com.google.common.collect.ImmutableList)3