Search in sources :

Example 1 with ClusterStatusResponse

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

the class ClusterStatusResourceTest method shouldReturnEmptyLagsForDeadHost.

@Test
public void shouldReturnEmptyLagsForDeadHost() {
    // Given:
    when(heartbeatAgent.getHostsStatus()).thenReturn(HOSTS);
    when(lagReportingAgent.getLagPerHost(any())).thenReturn(Optional.of(HOST_STORE_LAGS));
    // When:
    final EndpointResponse response = clusterStatusResource.checkClusterStatus();
    // Then:
    assertThat(response.getStatus(), is(200));
    assertThat(response.getEntity(), instanceOf(ClusterStatusResponse.class));
    ClusterStatusResponse clusterStatusResponse = (ClusterStatusResponse) response.getEntity();
    assertEquals(HOST_STORE_LAGS, clusterStatusResponse.getClusterStatus().get(HOST1_ENTITY).getHostStoreLags());
    assertEquals(EMPTY_HOST_STORE_LAGS, clusterStatusResponse.getClusterStatus().get(HOST2_ENTITY).getHostStoreLags());
}
Also used : EndpointResponse(io.confluent.ksql.rest.EndpointResponse) ClusterStatusResponse(io.confluent.ksql.rest.entity.ClusterStatusResponse) Test(org.junit.Test)

Example 2 with ClusterStatusResponse

use of io.confluent.ksql.rest.entity.ClusterStatusResponse 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 3 with ClusterStatusResponse

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

the class LagReportingAgentFunctionalTest method shouldExchangeLags.

@Test(timeout = 60000)
public void shouldExchangeLags() {
    // Given:
    waitForClusterCondition(LagReportingAgentFunctionalTest::allServersDiscovered);
    // When:
    ClusterStatusResponse resp = waitForClusterCondition(LagReportingAgentFunctionalTest::allLagsReported);
    StateStoreLags stateStoreLags = resp.getClusterStatus().entrySet().iterator().next().getValue().getHostStoreLags().getStateStoreLags(STORE_0).get();
    // Then:
    // Read the raw Kafka data from the topic to verify the reported lags
    final List<ConsumerRecord<byte[], byte[]>> records = TEST_HARNESS.verifyAvailableRecords("_confluent-ksql-default_query_CTAS_USER_VIEWS_3-" + "Aggregate-Aggregate-Materialize-changelog", NUM_ROWS);
    Map<Integer, Optional<ConsumerRecord<byte[], byte[]>>> partitionToMaxOffset = records.stream().collect(Collectors.groupingBy(ConsumerRecord::partition, Collectors.maxBy(Comparator.comparingLong(ConsumerRecord::offset))));
    Assert.assertEquals(2, partitionToMaxOffset.size());
    Optional<LagInfoEntity> lagInfoEntity0 = stateStoreLags.getLagByPartition(0);
    Optional<LagInfoEntity> lagInfoEntity1 = stateStoreLags.getLagByPartition(1);
    long partition0Offset = lagInfoEntity0.get().getCurrentOffsetPosition();
    long partition1Offset = lagInfoEntity1.get().getCurrentOffsetPosition();
    Assert.assertEquals(partition0Offset, partitionToMaxOffset.get(0).get().offset() + 1);
    Assert.assertEquals(partition1Offset, partitionToMaxOffset.get(1).get().offset() + 1);
}
Also used : LagInfoEntity(io.confluent.ksql.rest.entity.LagInfoEntity) Optional(java.util.Optional) ClusterStatusResponse(io.confluent.ksql.rest.entity.ClusterStatusResponse) StateStoreLags(io.confluent.ksql.rest.entity.StateStoreLags) ConsumerRecord(org.apache.kafka.clients.consumer.ConsumerRecord) IntegrationTest(io.confluent.common.utils.IntegrationTest) Test(org.junit.Test)

Example 4 with ClusterStatusResponse

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

the class HeartbeatAgentFunctionalTest method shouldMarkRemoteServerAsDown.

@Test(timeout = 60000)
public void shouldMarkRemoteServerAsDown() {
    // Given:
    waitForClusterToBeDiscovered(REST_APP_0, 2);
    // When:
    ClusterStatusResponse clusterStatusResponse = waitForRemoteServerToChangeStatus(REST_APP_0, host1, HighAvailabilityTestUtil::remoteServerIsDown);
    // Then:
    assertThat(clusterStatusResponse.getClusterStatus().get(host0).getHostAlive(), is(true));
    assertThat(clusterStatusResponse.getClusterStatus().get(host1).getHostAlive(), is(false));
}
Also used : ClusterStatusResponse(io.confluent.ksql.rest.entity.ClusterStatusResponse) IntegrationTest(io.confluent.common.utils.IntegrationTest) Test(org.junit.Test)

Example 5 with ClusterStatusResponse

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

the class HeartbeatAgentFunctionalTest method shouldMarkServersAsUp.

@Test(timeout = 60000)
public void shouldMarkServersAsUp() {
    // Given:
    waitForClusterToBeDiscovered(REST_APP_0, 2);
    waitForRemoteServerToChangeStatus(REST_APP_0, host1, HighAvailabilityTestUtil::remoteServerIsDown);
    // When:
    sendHeartbeartsForWindowLength(REST_APP_0, host1, 3000);
    final ClusterStatusResponse clusterStatusResponseUp = waitForRemoteServerToChangeStatus(REST_APP_0, host1, HighAvailabilityTestUtil::remoteServerIsUp);
    // Then:
    assertThat(clusterStatusResponseUp.getClusterStatus().get(host0).getHostAlive(), is(true));
    assertThat(clusterStatusResponseUp.getClusterStatus().get(host1).getHostAlive(), is(true));
}
Also used : ClusterStatusResponse(io.confluent.ksql.rest.entity.ClusterStatusResponse) IntegrationTest(io.confluent.common.utils.IntegrationTest) Test(org.junit.Test)

Aggregations

ClusterStatusResponse (io.confluent.ksql.rest.entity.ClusterStatusResponse)11 Test (org.junit.Test)8 IntegrationTest (io.confluent.common.utils.IntegrationTest)5 EndpointResponse (io.confluent.ksql.rest.EndpointResponse)2 ActiveStandbyEntity (io.confluent.ksql.rest.entity.ActiveStandbyEntity)2 KsqlHostInfoEntity (io.confluent.ksql.rest.entity.KsqlHostInfoEntity)2 LagInfoEntity (io.confluent.ksql.rest.entity.LagInfoEntity)2 StreamedRow (io.confluent.ksql.rest.entity.StreamedRow)2 Optional (java.util.Optional)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 BasicCredentials (io.confluent.ksql.rest.client.BasicCredentials)1 KsqlRestClient (io.confluent.ksql.rest.client.KsqlRestClient)1 RestResponse (io.confluent.ksql.rest.client.RestResponse)1 HeartbeatResponse (io.confluent.ksql.rest.entity.HeartbeatResponse)1 HostStatusEntity (io.confluent.ksql.rest.entity.HostStatusEntity)1 KsqlEntity (io.confluent.ksql.rest.entity.KsqlEntity)1 LagReportingMessage (io.confluent.ksql.rest.entity.LagReportingMessage)1 StateStoreLags (io.confluent.ksql.rest.entity.StateStoreLags)1 TestKsqlRestApp (io.confluent.ksql.rest.server.TestKsqlRestApp)1 KsqlRequestConfig (io.confluent.ksql.util.KsqlRequestConfig)1