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)));
}
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)));
}
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);
}
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
}
}
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)));
}
Aggregations