Search in sources :

Example 6 with QueryDescriptionList

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

Example 7 with QueryDescriptionList

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)));
}
Also used : QueryDescriptionList(io.confluent.ksql.rest.entity.QueryDescriptionList) KsqlHostInfoEntity(io.confluent.ksql.rest.entity.KsqlHostInfoEntity) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) PersistentQueryMetadata(io.confluent.ksql.util.PersistentQueryMetadata) Test(org.junit.Test)

Example 8 with QueryDescriptionList

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;
}
Also used : QueryId(io.confluent.ksql.query.QueryId) QueryDescriptionList(io.confluent.ksql.rest.entity.QueryDescriptionList) KsqlHostInfoEntity(io.confluent.ksql.rest.entity.KsqlHostInfoEntity) QueryDescription(io.confluent.ksql.rest.entity.QueryDescription) Map(java.util.Map) HostInfo(org.apache.kafka.streams.state.HostInfo) KsqlQueryStatus(io.confluent.ksql.util.KsqlConstants.KsqlQueryStatus)

Aggregations

QueryDescriptionList (io.confluent.ksql.rest.entity.QueryDescriptionList)8 KsqlHostInfoEntity (io.confluent.ksql.rest.entity.KsqlHostInfoEntity)6 PersistentQueryMetadata (io.confluent.ksql.util.PersistentQueryMetadata)6 Test (org.junit.Test)6 KsqlEngine (io.confluent.ksql.engine.KsqlEngine)5 ListQueries (io.confluent.ksql.parser.tree.ListQueries)5 ConfiguredStatement (io.confluent.ksql.statement.ConfiguredStatement)5 KsqlQueryStatus (io.confluent.ksql.util.KsqlConstants.KsqlQueryStatus)5 QueryDescription (io.confluent.ksql.rest.entity.QueryDescription)4 HashMap (java.util.HashMap)3 QueryId (io.confluent.ksql.query.QueryId)1 KsqlRestClientException (io.confluent.ksql.rest.client.exception.KsqlRestClientException)1 KsqlEntity (io.confluent.ksql.rest.entity.KsqlEntity)1 KsqlErrorMessage (io.confluent.ksql.rest.entity.KsqlErrorMessage)1 StreamsTaskMetadata (io.confluent.ksql.rest.entity.StreamsTaskMetadata)1 Map (java.util.Map)1 HostInfo (org.apache.kafka.streams.state.HostInfo)1 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1