Search in sources :

Example 1 with KsqlQueryStatus

use of io.confluent.ksql.util.KsqlConstants.KsqlQueryStatus in project ksql by confluentinc.

the class ListQueriesExecutorTest method shouldNotMergeDifferentQueryDescriptions.

@Test
public void shouldNotMergeDifferentQueryDescriptions() {
    // Given
    when(sessionProperties.getInternalRequest()).thenReturn(false);
    final ConfiguredStatement<ListQueries> showQueries = (ConfiguredStatement<ListQueries>) engine.configure("SHOW QUERIES EXTENDED;");
    final PersistentQueryMetadata localMetadata = givenPersistentQuery("id", RUNNING_QUERY_STATE);
    final PersistentQueryMetadata remoteMetadata = givenPersistentQuery("different id", ERROR_QUERY_STATE);
    final KsqlEngine engine = mock(KsqlEngine.class);
    when(engine.getAllLiveQueries()).thenReturn(ImmutableList.of(localMetadata));
    when(engine.getPersistentQueries()).thenReturn(ImmutableList.of(localMetadata));
    final Map<KsqlHostInfoEntity, KsqlQueryStatus> remoteMap = Collections.singletonMap(REMOTE_KSQL_HOST_INFO_ENTITY, KsqlQueryStatus.RUNNING);
    final List<QueryDescription> remoteQueryDescriptions = Collections.singletonList(QueryDescriptionFactory.forQueryMetadata(remoteMetadata, remoteMap));
    when(remoteQueryDescriptionList.getQueryDescriptions()).thenReturn(remoteQueryDescriptions);
    when(ksqlEntityList.get(anyInt())).thenReturn(remoteQueryDescriptionList);
    when(response.getResponse()).thenReturn(ksqlEntityList);
    // When
    final QueryDescriptionList queries = (QueryDescriptionList) CUSTOM_EXECUTORS.listQueries().execute(showQueries, sessionProperties, engine, serviceContext).getEntity().orElseThrow(IllegalStateException::new);
    // Then
    assertThat(queries.getQueryDescriptions(), containsInAnyOrder(QueryDescriptionFactory.forQueryMetadata(localMetadata, LOCAL_KSQL_HOST_INFO_MAP), QueryDescriptionFactory.forQueryMetadata(remoteMetadata, remoteMap)));
}
Also used : ConfiguredStatement(io.confluent.ksql.statement.ConfiguredStatement) KsqlEngine(io.confluent.ksql.engine.KsqlEngine) ListQueries(io.confluent.ksql.parser.tree.ListQueries) QueryDescriptionList(io.confluent.ksql.rest.entity.QueryDescriptionList) KsqlHostInfoEntity(io.confluent.ksql.rest.entity.KsqlHostInfoEntity) QueryDescription(io.confluent.ksql.rest.entity.QueryDescription) PersistentQueryMetadata(io.confluent.ksql.util.PersistentQueryMetadata) KsqlQueryStatus(io.confluent.ksql.util.KsqlConstants.KsqlQueryStatus) Test(org.junit.Test)

Example 2 with KsqlQueryStatus

use of io.confluent.ksql.util.KsqlConstants.KsqlQueryStatus in project ksql by confluentinc.

the class ListQueriesExecutorTest method shouldScatterGatherAndMergeShowQueriesExtended.

@Test
public void shouldScatterGatherAndMergeShowQueriesExtended() {
    // Given
    when(sessionProperties.getInternalRequest()).thenReturn(false);
    final ConfiguredStatement<ListQueries> showQueries = (ConfiguredStatement<ListQueries>) engine.configure("SHOW QUERIES EXTENDED;");
    final StreamsTaskMetadata localTaskMetadata = mock(StreamsTaskMetadata.class);
    final StreamsTaskMetadata remoteTaskMetadata = mock(StreamsTaskMetadata.class);
    final PersistentQueryMetadata localMetadata = givenPersistentQuery("id", RUNNING_QUERY_STATE, Collections.singleton(localTaskMetadata));
    final PersistentQueryMetadata remoteMetadata = givenPersistentQuery("id", ERROR_QUERY_STATE, Collections.singleton(remoteTaskMetadata));
    final KsqlEngine engine = mock(KsqlEngine.class);
    when(engine.getAllLiveQueries()).thenReturn(ImmutableList.of(localMetadata));
    when(engine.getPersistentQueries()).thenReturn(ImmutableList.of(localMetadata));
    final List<QueryDescription> remoteQueryDescriptions = Collections.singletonList(QueryDescriptionFactory.forQueryMetadata(remoteMetadata, Collections.singletonMap(REMOTE_KSQL_HOST_INFO_ENTITY, KsqlQueryStatus.ERROR)));
    when(remoteQueryDescriptionList.getQueryDescriptions()).thenReturn(remoteQueryDescriptions);
    when(ksqlEntityList.get(anyInt())).thenReturn(remoteQueryDescriptionList);
    when(response.getResponse()).thenReturn(ksqlEntityList);
    final Map<KsqlHostInfoEntity, KsqlQueryStatus> mergedMap = new HashMap<>();
    mergedMap.put(REMOTE_KSQL_HOST_INFO_ENTITY, KsqlQueryStatus.ERROR);
    mergedMap.put(LOCAL_KSQL_HOST_INFO_ENTITY, KsqlQueryStatus.RUNNING);
    // When
    final QueryDescriptionList queries = (QueryDescriptionList) CUSTOM_EXECUTORS.listQueries().execute(showQueries, sessionProperties, engine, serviceContext).getEntity().orElseThrow(IllegalStateException::new);
    // Then
    final QueryDescription mergedQueryDescription = QueryDescriptionFactory.forQueryMetadata(localMetadata, mergedMap);
    mergedQueryDescription.updateTaskMetadata(Collections.singleton(remoteTaskMetadata));
    assertThat(queries.getQueryDescriptions(), containsInAnyOrder(mergedQueryDescription));
}
Also used : KsqlEngine(io.confluent.ksql.engine.KsqlEngine) HashMap(java.util.HashMap) ListQueries(io.confluent.ksql.parser.tree.ListQueries) QueryDescription(io.confluent.ksql.rest.entity.QueryDescription) StreamsTaskMetadata(io.confluent.ksql.rest.entity.StreamsTaskMetadata) ConfiguredStatement(io.confluent.ksql.statement.ConfiguredStatement) 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 3 with KsqlQueryStatus

use of io.confluent.ksql.util.KsqlConstants.KsqlQueryStatus in project ksql by confluentinc.

the class ListQueriesExecutorTest method shouldIncludeUnresponsiveIfShowQueriesExtendedErrorResponse.

@Test
public void shouldIncludeUnresponsiveIfShowQueriesExtendedErrorResponse() {
    // 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(response.isErroneous()).thenReturn(true);
    when(response.getErrorMessage()).thenReturn(new KsqlErrorMessage(10000, "error"));
    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) 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) KsqlErrorMessage(io.confluent.ksql.rest.entity.KsqlErrorMessage) KsqlQueryStatus(io.confluent.ksql.util.KsqlConstants.KsqlQueryStatus) Test(org.junit.Test)

Example 4 with KsqlQueryStatus

use of io.confluent.ksql.util.KsqlConstants.KsqlQueryStatus 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 5 with KsqlQueryStatus

use of io.confluent.ksql.util.KsqlConstants.KsqlQueryStatus in project ksql by confluentinc.

the class ListQueriesExecutor method mergeSimple.

private static Map<QueryId, RunningQuery> mergeSimple(final Map<QueryId, RunningQuery> allResults, final Pair<Map<HostInfo, KsqlEntity>, Set<HostInfo>> remoteResults) {
    final List<RunningQuery> remoteRunningQueries = remoteResults.getLeft().values().stream().map(Queries.class::cast).map(Queries::getQueries).flatMap(List::stream).collect(Collectors.toList());
    for (RunningQuery q : remoteRunningQueries) {
        final QueryId queryId = q.getId();
        // If the query has already been discovered, update the QueryStatusCount object
        if (allResults.containsKey(queryId)) {
            for (Map.Entry<KsqlQueryStatus, Integer> entry : q.getStatusCount().getStatuses().entrySet()) {
                allResults.get(queryId).getStatusCount().updateStatusCount(entry.getKey(), entry.getValue());
            }
        } else {
            allResults.put(queryId, q);
        }
    }
    final Set<HostInfo> unresponsiveRemoteHosts = remoteResults.getRight();
    if (!unresponsiveRemoteHosts.isEmpty()) {
        for (RunningQuery runningQuery : allResults.values()) {
            runningQuery.getStatusCount().updateStatusCount(KsqlQueryStatus.UNRESPONSIVE, unresponsiveRemoteHosts.size());
        }
    }
    return allResults;
}
Also used : RunningQuery(io.confluent.ksql.rest.entity.RunningQuery) Queries(io.confluent.ksql.rest.entity.Queries) ListQueries(io.confluent.ksql.parser.tree.ListQueries) QueryId(io.confluent.ksql.query.QueryId) Map(java.util.Map) HostInfo(org.apache.kafka.streams.state.HostInfo) KsqlQueryStatus(io.confluent.ksql.util.KsqlConstants.KsqlQueryStatus)

Aggregations

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