Search in sources :

Example 6 with ClusterStatusResponse

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

the class HeartbeatAgentFunctionalTest method shouldMarkRemoteServerAsUpThenDownThenUp.

@Test(timeout = 60000)
public void shouldMarkRemoteServerAsUpThenDownThenUp() {
    // Given:
    waitForClusterToBeDiscovered(REST_APP_0, 2);
    sendHeartbeartsForWindowLength(REST_APP_0, host1, 3000);
    // When:
    final ClusterStatusResponse clusterStatusResponseUp1 = waitForRemoteServerToChangeStatus(REST_APP_0, host1, HighAvailabilityTestUtil::remoteServerIsUp);
    // Then:
    assertThat(clusterStatusResponseUp1.getClusterStatus().get(host0).getHostAlive(), is(true));
    assertThat(clusterStatusResponseUp1.getClusterStatus().get(host1).getHostAlive(), is(true));
    // When:
    ClusterStatusResponse clusterStatusResponseDown = waitForRemoteServerToChangeStatus(REST_APP_0, host1, HighAvailabilityTestUtil::remoteServerIsDown);
    // Then:
    assertThat(clusterStatusResponseDown.getClusterStatus().get(host0).getHostAlive(), is(true));
    assertThat(clusterStatusResponseDown.getClusterStatus().get(host1).getHostAlive(), is(false));
    // When :
    sendHeartbeartsForWindowLength(REST_APP_0, host1, 3000);
    ClusterStatusResponse clusterStatusResponseUp2 = waitForRemoteServerToChangeStatus(REST_APP_0, host1, HighAvailabilityTestUtil::remoteServerIsUp);
    // Then:
    assertThat(clusterStatusResponseUp2.getClusterStatus().get(host0).getHostAlive(), is(true));
    assertThat(clusterStatusResponseUp2.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)

Example 7 with ClusterStatusResponse

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

the class KsqlClientTest method shouldRequestClusterStatus.

@Test
public void shouldRequestClusterStatus() {
    // Given:
    ClusterStatusResponse clusterStatusResponse = new ClusterStatusResponse(new HashMap<>());
    server.setResponseObject(clusterStatusResponse);
    // When:
    KsqlTarget target = ksqlClient.target(serverUri);
    RestResponse<ClusterStatusResponse> response = target.getClusterStatus();
    // Then:
    assertThat(server.getHttpMethod(), is(HttpMethod.GET));
    assertThat(server.getBody().length(), is(0));
    // Yikes - this is camel case!
    assertThat(server.getPath(), is("/clusterStatus"));
    assertThat(server.getHeaders().get("Accept"), is("application/json"));
    assertThat(response.get(), is(clusterStatusResponse));
}
Also used : ClusterStatusResponse(io.confluent.ksql.rest.entity.ClusterStatusResponse) Test(org.junit.Test)

Example 8 with ClusterStatusResponse

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

the class PullQueryConsistencyFunctionalTest method findClusterFormation.

private ClusterFormation findClusterFormation(TestApp testApp0, TestApp testApp1, TestApp testApp2) {
    ClusterFormation clusterFormation = new ClusterFormation();
    ClusterStatusResponse clusterStatusResponse = HighAvailabilityTestUtil.sendClusterStatusRequest(testApp0.getApp(), USER_CREDS);
    ActiveStandbyEntity entity0 = clusterStatusResponse.getClusterStatus().get(testApp0.getHost()).getActiveStandbyPerQuery().get(queryId);
    ActiveStandbyEntity entity1 = clusterStatusResponse.getClusterStatus().get(testApp1.getHost()).getActiveStandbyPerQuery().get(queryId);
    // find active
    if (!entity0.getActiveStores().isEmpty() && !entity0.getActivePartitions().isEmpty()) {
        clusterFormation.setActive(testApp0);
    } else if (!entity1.getActiveStores().isEmpty() && !entity1.getActivePartitions().isEmpty()) {
        clusterFormation.setActive(testApp1);
    } else {
        clusterFormation.setActive(testApp2);
    }
    // find standby
    if (!entity0.getStandByStores().isEmpty() && !entity0.getStandByPartitions().isEmpty()) {
        clusterFormation.setStandBy(testApp0);
    } else if (!entity1.getStandByStores().isEmpty() && !entity1.getStandByPartitions().isEmpty()) {
        clusterFormation.setStandBy(testApp1);
    } else {
        clusterFormation.setStandBy(testApp2);
    }
    // find router
    if (entity0.getStandByStores().isEmpty() && entity0.getActiveStores().isEmpty()) {
        clusterFormation.setRouter(testApp0);
    } else if (entity1.getStandByStores().isEmpty() && entity1.getActiveStores().isEmpty()) {
        clusterFormation.setRouter(testApp1);
    } else {
        clusterFormation.setRouter(testApp2);
    }
    return clusterFormation;
}
Also used : ClusterStatusResponse(io.confluent.ksql.rest.entity.ClusterStatusResponse) ActiveStandbyEntity(io.confluent.ksql.rest.entity.ActiveStandbyEntity)

Example 9 with ClusterStatusResponse

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

the class PullQuerySingleNodeFunctionalTest method restoreAfterClearState.

@Ignore
@Test
public void restoreAfterClearState() {
    waitForStreamsMetadataToInitialize(REST_APP_0, ImmutableList.of(host0));
    waitForRemoteServerToChangeStatus(REST_APP_0, host0, HighAvailabilityTestUtil.lagsReported(host0, Optional.empty(), 5));
    // When:
    final List<StreamedRow> rows_0 = makePullQueryRequest(REST_APP_0, sql, LAG_FILTER_3);
    // Then:
    assertThat(rows_0, hasSize(HEADER + 1));
    KsqlHostInfoEntity host = rows_0.get(1).getSourceHost().get();
    assertThat(host.getHost(), is(host0.getHost()));
    assertThat(host.getPort(), is(host0.getPort()));
    assertThat(rows_0.get(1).getRow(), is(not(Optional.empty())));
    assertThat(rows_0.get(1).getRow().get().getColumns(), is(ImmutableList.of(KEY, 1)));
    // Stop the server and blow away the state
    LOG.info("Shutting down the server " + host0.toString());
    REST_APP_0.stop();
    String stateDir = (String) REST_APP_0.getBaseConfig().get(KSQL_STREAMS_PREFIX + StreamsConfig.STATE_DIR_CONFIG);
    clearDir(stateDir);
    // Pause incoming kafka consumption
    APP_SHUTOFFS_0.setKafkaPauseOffset(2);
    LOG.info("Restarting the server " + host0.toString());
    REST_APP_0.start();
    waitForStreamsMetadataToInitialize(REST_APP_0, ImmutableList.of(host0));
    waitForRemoteServerToChangeStatus(REST_APP_0, host0, HighAvailabilityTestUtil.lagsReported(host0, Optional.of(2L), 5));
    ClusterStatusResponse clusterStatusResponse = HighAvailabilityTestUtil.sendClusterStatusRequest(REST_APP_0);
    Pair<Long, Long> pair = getOffsets(host0, clusterStatusResponse.getClusterStatus());
    assertThat(pair.left, is(2L));
    assertThat(pair.right, is(5L));
    final List<StreamedRow> sameRows = makePullQueryRequest(REST_APP_0, sql, LAG_FILTER_3);
    host = sameRows.get(1).getSourceHost().get();
    assertThat(host.getHost(), is(host0.getHost()));
    assertThat(host.getPort(), is(host0.getPort()));
    assertThat(sameRows.get(1).getRow(), is(not(Optional.empty())));
    // Still haven't gotten the update yet
    assertThat(sameRows.get(1).getRow().get().getColumns(), is(ImmutableList.of(KEY, 1)));
    // Row not found!
    final List<StreamedRow> headerOnly = makePullQueryRequest(REST_APP_0, sqlKey3, LAG_FILTER_3);
    assertThat(headerOnly.size(), is(1));
    // Unpause incoming kafka consumption. We then expect active to catch back up.
    APP_SHUTOFFS_0.setKafkaPauseOffset(-1);
    waitForRemoteServerToChangeStatus(REST_APP_0, host0, HighAvailabilityTestUtil.lagsReported(host0, Optional.of(5L), 5));
    clusterStatusResponse = HighAvailabilityTestUtil.sendClusterStatusRequest(REST_APP_0);
    pair = getOffsets(host0, clusterStatusResponse.getClusterStatus());
    assertThat(pair.left, is(5L));
    assertThat(pair.right, is(5L));
    final List<StreamedRow> updatedRows = makePullQueryRequest(REST_APP_0, sqlKey3, LAG_FILTER_3);
    // Now it is found!
    host = updatedRows.get(1).getSourceHost().get();
    assertThat(host.getHost(), is(host0.getHost()));
    assertThat(host.getPort(), is(host0.getPort()));
    assertThat(updatedRows.get(1).getRow(), is(not(Optional.empty())));
    assertThat(updatedRows.get(1).getRow().get().getColumns(), is(ImmutableList.of(KEY_3, 1)));
}
Also used : StreamedRow(io.confluent.ksql.rest.entity.StreamedRow) ClusterStatusResponse(io.confluent.ksql.rest.entity.ClusterStatusResponse) AtomicLong(java.util.concurrent.atomic.AtomicLong) KsqlHostInfoEntity(io.confluent.ksql.rest.entity.KsqlHostInfoEntity) Ignore(org.junit.Ignore) IntegrationTest(io.confluent.common.utils.IntegrationTest) Test(org.junit.Test)

Example 10 with ClusterStatusResponse

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

the class PullQueryRoutingFunctionalTest method findClusterFormation.

private ClusterFormation findClusterFormation(TestApp testApp0, TestApp testApp1, TestApp testApp2) {
    ClusterFormation clusterFormation = new ClusterFormation();
    ClusterStatusResponse clusterStatusResponse = HighAvailabilityTestUtil.sendClusterStatusRequest(testApp0.getApp(), USER_CREDS);
    ActiveStandbyEntity entity0 = clusterStatusResponse.getClusterStatus().get(testApp0.getHost()).getActiveStandbyPerQuery().get(queryId);
    ActiveStandbyEntity entity1 = clusterStatusResponse.getClusterStatus().get(testApp1.getHost()).getActiveStandbyPerQuery().get(queryId);
    // find active
    if (!entity0.getActiveStores().isEmpty() && !entity0.getActivePartitions().isEmpty()) {
        clusterFormation.setActive(testApp0);
    } else if (!entity1.getActiveStores().isEmpty() && !entity1.getActivePartitions().isEmpty()) {
        clusterFormation.setActive(testApp1);
    } else {
        clusterFormation.setActive(testApp2);
    }
    // find standby
    if (!entity0.getStandByStores().isEmpty() && !entity0.getStandByPartitions().isEmpty()) {
        clusterFormation.setStandBy(testApp0);
    } else if (!entity1.getStandByStores().isEmpty() && !entity1.getStandByPartitions().isEmpty()) {
        clusterFormation.setStandBy(testApp1);
    } else {
        clusterFormation.setStandBy(testApp2);
    }
    // find router
    if (entity0.getStandByStores().isEmpty() && entity0.getActiveStores().isEmpty()) {
        clusterFormation.setRouter(testApp0);
    } else if (entity1.getStandByStores().isEmpty() && entity1.getActiveStores().isEmpty()) {
        clusterFormation.setRouter(testApp1);
    } else {
        clusterFormation.setRouter(testApp2);
    }
    return clusterFormation;
}
Also used : ClusterStatusResponse(io.confluent.ksql.rest.entity.ClusterStatusResponse) ActiveStandbyEntity(io.confluent.ksql.rest.entity.ActiveStandbyEntity)

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