Search in sources :

Example 1 with HostStatusEntity

use of io.confluent.ksql.rest.entity.HostStatusEntity 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);
}
Also used : StreamedRow(io.confluent.ksql.rest.entity.StreamedRow) BiFunction(java.util.function.BiFunction) LoggerFactory(org.slf4j.LoggerFactory) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ClusterStatusResponse(io.confluent.ksql.rest.entity.ClusterStatusResponse) LagInfoEntity(io.confluent.ksql.rest.entity.LagInfoEntity) RestResponse(io.confluent.ksql.rest.client.RestResponse) HeartbeatResponse(io.confluent.ksql.rest.entity.HeartbeatResponse) Function(java.util.function.Function) KsqlEntity(io.confluent.ksql.rest.entity.KsqlEntity) KsqlHostInfoEntity(io.confluent.ksql.rest.entity.KsqlHostInfoEntity) KsqlRestClient(io.confluent.ksql.rest.client.KsqlRestClient) Pair(io.confluent.ksql.util.Pair) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) LagReportingMessage(io.confluent.ksql.rest.entity.LagReportingMessage) HostStatusEntity(io.confluent.ksql.rest.entity.HostStatusEntity) KsqlRequestConfig(io.confluent.ksql.util.KsqlRequestConfig) Logger(org.slf4j.Logger) ImmutableMap(com.google.common.collect.ImmutableMap) TestKsqlRestApp(io.confluent.ksql.rest.server.TestKsqlRestApp) BasicCredentials(io.confluent.ksql.rest.client.BasicCredentials) Collectors(java.util.stream.Collectors) ExecutionException(java.util.concurrent.ExecutionException) List(java.util.List) Entry(java.util.Map.Entry) Optional(java.util.Optional) Pattern(java.util.regex.Pattern) LagInfoEntity(io.confluent.ksql.rest.entity.LagInfoEntity) HostStatusEntity(io.confluent.ksql.rest.entity.HostStatusEntity)

Example 2 with HostStatusEntity

use of io.confluent.ksql.rest.entity.HostStatusEntity 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
    }
}
Also used : StreamedRow(io.confluent.ksql.rest.entity.StreamedRow) BiFunction(java.util.function.BiFunction) LoggerFactory(org.slf4j.LoggerFactory) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ClusterStatusResponse(io.confluent.ksql.rest.entity.ClusterStatusResponse) LagInfoEntity(io.confluent.ksql.rest.entity.LagInfoEntity) RestResponse(io.confluent.ksql.rest.client.RestResponse) HeartbeatResponse(io.confluent.ksql.rest.entity.HeartbeatResponse) Function(java.util.function.Function) KsqlEntity(io.confluent.ksql.rest.entity.KsqlEntity) KsqlHostInfoEntity(io.confluent.ksql.rest.entity.KsqlHostInfoEntity) KsqlRestClient(io.confluent.ksql.rest.client.KsqlRestClient) Pair(io.confluent.ksql.util.Pair) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) LagReportingMessage(io.confluent.ksql.rest.entity.LagReportingMessage) HostStatusEntity(io.confluent.ksql.rest.entity.HostStatusEntity) KsqlRequestConfig(io.confluent.ksql.util.KsqlRequestConfig) Logger(org.slf4j.Logger) ImmutableMap(com.google.common.collect.ImmutableMap) TestKsqlRestApp(io.confluent.ksql.rest.server.TestKsqlRestApp) BasicCredentials(io.confluent.ksql.rest.client.BasicCredentials) Collectors(java.util.stream.Collectors) ExecutionException(java.util.concurrent.ExecutionException) List(java.util.List) Entry(java.util.Map.Entry) Optional(java.util.Optional) Pattern(java.util.regex.Pattern) ClusterStatusResponse(io.confluent.ksql.rest.entity.ClusterStatusResponse) KsqlHostInfoEntity(io.confluent.ksql.rest.entity.KsqlHostInfoEntity) ExecutionException(java.util.concurrent.ExecutionException)

Aggregations

ImmutableMap (com.google.common.collect.ImmutableMap)2 BasicCredentials (io.confluent.ksql.rest.client.BasicCredentials)2 KsqlRestClient (io.confluent.ksql.rest.client.KsqlRestClient)2 RestResponse (io.confluent.ksql.rest.client.RestResponse)2 ClusterStatusResponse (io.confluent.ksql.rest.entity.ClusterStatusResponse)2 HeartbeatResponse (io.confluent.ksql.rest.entity.HeartbeatResponse)2 HostStatusEntity (io.confluent.ksql.rest.entity.HostStatusEntity)2 KsqlEntity (io.confluent.ksql.rest.entity.KsqlEntity)2 KsqlHostInfoEntity (io.confluent.ksql.rest.entity.KsqlHostInfoEntity)2 LagInfoEntity (io.confluent.ksql.rest.entity.LagInfoEntity)2 LagReportingMessage (io.confluent.ksql.rest.entity.LagReportingMessage)2 StreamedRow (io.confluent.ksql.rest.entity.StreamedRow)2 TestKsqlRestApp (io.confluent.ksql.rest.server.TestKsqlRestApp)2 KsqlRequestConfig (io.confluent.ksql.util.KsqlRequestConfig)2 Pair (io.confluent.ksql.util.Pair)2 List (java.util.List)2 Map (java.util.Map)2 Entry (java.util.Map.Entry)2 Optional (java.util.Optional)2 ExecutionException (java.util.concurrent.ExecutionException)2