use of io.confluent.ksql.rest.entity.QueryDescriptionList 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)));
}
use of io.confluent.ksql.rest.entity.QueryDescriptionList in project ksql by confluentinc.
the class KsqlResourceTest method shouldShowQueriesExtended.
@Test
public void shouldShowQueriesExtended() {
// Given:
final Map<String, Object> overriddenProperties = Collections.singletonMap("ksql.streams.auto.offset.reset", "earliest");
final List<PersistentQueryMetadata> queryMetadata = createQueries("CREATE STREAM test_describe_1 AS SELECT * FROM test_stream;" + "CREATE STREAM test_describe_2 AS SELECT * FROM test_stream;", overriddenProperties);
// When:
final QueryDescriptionList descriptionList = makeSingleRequest("SHOW QUERIES EXTENDED;", QueryDescriptionList.class);
final Map<KsqlHostInfoEntity, KsqlConstants.KsqlQueryStatus> queryHostState = ImmutableMap.of(new KsqlHostInfoEntity(APPLICATION_HOST, APPLICATION_PORT), KsqlConstants.KsqlQueryStatus.RUNNING);
// Then:
assertThat(descriptionList.getQueryDescriptions(), containsInAnyOrder(QueryDescriptionFactory.forQueryMetadata(queryMetadata.get(0), queryHostState), QueryDescriptionFactory.forQueryMetadata(queryMetadata.get(1), queryHostState)));
}
use of io.confluent.ksql.rest.entity.QueryDescriptionList in project ksql by confluentinc.
the class ListQueriesExecutor method mergeExtended.
private static Map<QueryId, QueryDescription> mergeExtended(final Map<QueryId, QueryDescription> allResults, final Pair<Map<HostInfo, KsqlEntity>, Set<HostInfo>> remoteResults) {
final List<QueryDescription> remoteQueryDescriptions = remoteResults.getLeft().values().stream().map(QueryDescriptionList.class::cast).map(QueryDescriptionList::getQueryDescriptions).flatMap(List::stream).collect(Collectors.toList());
for (QueryDescription q : remoteQueryDescriptions) {
final QueryId queryId = q.getId();
// and the streams metadata task set
if (allResults.containsKey(queryId)) {
for (Map.Entry<KsqlHostInfoEntity, KsqlQueryStatus> entry : q.getKsqlHostQueryStatus().entrySet()) {
allResults.get(queryId).updateKsqlHostQueryStatus(entry.getKey(), entry.getValue());
}
allResults.get(queryId).updateTaskMetadata(q.getTasksMetadata());
} else {
allResults.put(queryId, q);
}
}
final Set<HostInfo> unresponsiveRemoteHosts = remoteResults.getRight();
for (HostInfo hostInfo : unresponsiveRemoteHosts) {
for (QueryDescription queryDescription : allResults.values()) {
queryDescription.updateKsqlHostQueryStatus(new KsqlHostInfoEntity(hostInfo.host(), hostInfo.port()), KsqlQueryStatus.UNRESPONSIVE);
}
}
return allResults;
}
Aggregations