Search in sources :

Example 6 with KsqlHostInfoEntity

use of io.confluent.ksql.rest.entity.KsqlHostInfoEntity 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 7 with KsqlHostInfoEntity

use of io.confluent.ksql.rest.entity.KsqlHostInfoEntity 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 8 with KsqlHostInfoEntity

use of io.confluent.ksql.rest.entity.KsqlHostInfoEntity 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 9 with KsqlHostInfoEntity

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

the class KsqlClientTest method shouldSendHeartbeatRequest.

@Test
public void shouldSendHeartbeatRequest() throws Exception {
    // Given:
    KsqlHostInfoEntity entity = new KsqlHostInfoEntity(serverUri.getHost(), serverUri.getPort());
    long timestamp = System.currentTimeMillis();
    server.setResponseObject(new HeartbeatResponse(true));
    // When:
    KsqlTarget target = ksqlClient.target(serverUri);
    target.postAsyncHeartbeatRequest(entity, timestamp);
    Buffer body = server.waitForRequestBody();
    HeartbeatMessage hbm = KsqlClientUtil.deserialize(body, HeartbeatMessage.class);
    // Then:
    assertThat(server.getHttpMethod(), is(HttpMethod.POST));
    assertThat(server.getPath(), is("/heartbeat"));
    assertThat(server.getHeaders().get("Accept"), is("application/json"));
    assertThat(hbm, is(new HeartbeatMessage(entity, timestamp)));
}
Also used : Buffer(io.vertx.core.buffer.Buffer) HeartbeatResponse(io.confluent.ksql.rest.entity.HeartbeatResponse) HeartbeatMessage(io.confluent.ksql.rest.entity.HeartbeatMessage) KsqlHostInfoEntity(io.confluent.ksql.rest.entity.KsqlHostInfoEntity) Test(org.junit.Test)

Example 10 with KsqlHostInfoEntity

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

the class LagReportingAgentTest method shouldReceiveLags_listAllCurrentPositions.

@Test
public void shouldReceiveLags_listAllCurrentPositions() {
    // When:
    lagReportingAgent.receiveHostLag(hostLag(HOST_ENTITY1, LAG_MAP1, 100));
    lagReportingAgent.receiveHostLag(hostLag(HOST_ENTITY2, LAG_MAP2, 200));
    lagReportingAgent.onHostStatusUpdated(HOSTS_ALIVE);
    // Then:
    ImmutableMap<KsqlHostInfoEntity, HostStoreLags> allLags = lagReportingAgent.getAllLags();
    LagInfoEntity lag = allLags.get(HOST_ENTITY1).getStateStoreLags(QUERY_STORE_A).flatMap(s -> s.getLagByPartition(1)).get();
    assertEquals(M1_A1_CUR, lag.getCurrentOffsetPosition());
    assertEquals(M1_A1_END, lag.getEndOffsetPosition());
    assertEquals(M1_A1_LAG, lag.getOffsetLag());
    lag = allLags.get(HOST_ENTITY1).getStateStoreLags(QUERY_STORE_A).flatMap(s -> s.getLagByPartition(3)).get();
    assertEquals(M1_A3_CUR, lag.getCurrentOffsetPosition());
    assertEquals(M1_A3_END, lag.getEndOffsetPosition());
    assertEquals(M1_A3_LAG, lag.getOffsetLag());
    lag = allLags.get(HOST_ENTITY1).getStateStoreLags(QUERY_STORE_B).flatMap(s -> s.getLagByPartition(4)).get();
    assertEquals(M1_B4_CUR, lag.getCurrentOffsetPosition());
    assertEquals(M1_B4_END, lag.getEndOffsetPosition());
    assertEquals(M1_B4_LAG, lag.getOffsetLag());
    lag = allLags.get(HOST_ENTITY2).getStateStoreLags(QUERY_STORE_A).flatMap(s -> s.getLagByPartition(1)).get();
    assertEquals(M2_A1_CUR, lag.getCurrentOffsetPosition());
    assertEquals(M2_A1_END, lag.getEndOffsetPosition());
    assertEquals(M2_A1_LAG, lag.getOffsetLag());
    lag = allLags.get(HOST_ENTITY2).getStateStoreLags(QUERY_STORE_B).flatMap(s -> s.getLagByPartition(4)).get();
    assertEquals(M2_B4_CUR, lag.getCurrentOffsetPosition());
    assertEquals(M2_B4_END, lag.getEndOffsetPosition());
    assertEquals(M2_B4_LAG, lag.getOffsetLag());
}
Also used : StateStoreLags(io.confluent.ksql.rest.entity.StateStoreLags) Mock(org.mockito.Mock) HostStoreLags(io.confluent.ksql.rest.entity.HostStoreLags) ServiceContext(io.confluent.ksql.services.ServiceContext) RunWith(org.junit.runner.RunWith) LagInfoEntity(io.confluent.ksql.rest.entity.LagInfoEntity) KsqlHostInfo(io.confluent.ksql.util.KsqlHostInfo) KsqlHostInfoEntity(io.confluent.ksql.rest.entity.KsqlHostInfoEntity) ImmutableList(com.google.common.collect.ImmutableList) Map(java.util.Map) LagReportingMessage(io.confluent.ksql.rest.entity.LagReportingMessage) URI(java.net.URI) PersistentQueryMetadata(io.confluent.ksql.util.PersistentQueryMetadata) Before(org.junit.Before) ImmutableMap(com.google.common.collect.ImmutableMap) KsqlEngine(io.confluent.ksql.engine.KsqlEngine) Builder(io.confluent.ksql.rest.server.LagReportingAgent.Builder) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) SimpleKsqlClient(io.confluent.ksql.services.SimpleKsqlClient) Mockito.verify(org.mockito.Mockito.verify) SendLagService(io.confluent.ksql.rest.server.LagReportingAgent.SendLagService) LagInfo(org.apache.kafka.streams.LagInfo) Assert.assertFalse(org.junit.Assert.assertFalse) HostStatus(io.confluent.ksql.util.HostStatus) Clock(java.time.Clock) Optional(java.util.Optional) QueryStateStoreId(io.confluent.ksql.rest.entity.QueryStateStoreId) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) Assert.assertEquals(org.junit.Assert.assertEquals) Mockito.eq(org.mockito.Mockito.eq) HostStoreLags(io.confluent.ksql.rest.entity.HostStoreLags) LagInfoEntity(io.confluent.ksql.rest.entity.LagInfoEntity) KsqlHostInfoEntity(io.confluent.ksql.rest.entity.KsqlHostInfoEntity) Test(org.junit.Test)

Aggregations

KsqlHostInfoEntity (io.confluent.ksql.rest.entity.KsqlHostInfoEntity)23 Test (org.junit.Test)17 StreamedRow (io.confluent.ksql.rest.entity.StreamedRow)9 PersistentQueryMetadata (io.confluent.ksql.util.PersistentQueryMetadata)7 IntegrationTest (io.confluent.common.utils.IntegrationTest)6 KsqlEngine (io.confluent.ksql.engine.KsqlEngine)6 QueryDescriptionList (io.confluent.ksql.rest.entity.QueryDescriptionList)6 KsqlQueryStatus (io.confluent.ksql.util.KsqlConstants.KsqlQueryStatus)6 ImmutableMap (com.google.common.collect.ImmutableMap)5 QueryDescription (io.confluent.ksql.rest.entity.QueryDescription)5 ConfiguredStatement (io.confluent.ksql.statement.ConfiguredStatement)5 Map (java.util.Map)5 Optional (java.util.Optional)5 ListQueries (io.confluent.ksql.parser.tree.ListQueries)4 ClusterStatusResponse (io.confluent.ksql.rest.entity.ClusterStatusResponse)4 HeartbeatResponse (io.confluent.ksql.rest.entity.HeartbeatResponse)4 KsqlEntity (io.confluent.ksql.rest.entity.KsqlEntity)4 List (java.util.List)4 Collectors (java.util.stream.Collectors)4 ImmutableList (com.google.common.collect.ImmutableList)3