Search in sources :

Example 1 with TestKsqlRestApp

use of io.confluent.ksql.rest.server.TestKsqlRestApp 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)

Example 2 with TestKsqlRestApp

use of io.confluent.ksql.rest.server.TestKsqlRestApp in project ksql by confluentinc.

the class RestIntegrationTestUtil method rawRestRequest.

static VertxCompletableFuture<Void> rawRestRequest(final TestKsqlRestApp restApp, final HttpVersion httpVersion, final HttpMethod method, final String uri, final Object requestBody, final String mediaType, final Consumer<Buffer> chunkConsumer, final Optional<BasicCredentials> credentials) {
    final byte[] bytes;
    try {
        bytes = ApiJsonMapper.INSTANCE.get().writeValueAsBytes(requestBody);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    HttpClientOptions options = new HttpClientOptions().setDefaultPort(restApp.getHttpListener().getPort()).setDefaultHost(restApp.getHttpListener().getHost()).setVerifyHost(false);
    if (httpVersion == HttpVersion.HTTP_2) {
        options.setProtocolVersion(HttpVersion.HTTP_2);
    }
    final Vertx vertx = Vertx.vertx();
    final HttpClient httpClient = vertx.createHttpClient(options);
    final VertxCompletableFuture<Void> vcf = new VertxCompletableFuture<>();
    final HttpClientRequest httpClientRequest = httpClient.request(method, uri, resp -> {
        resp.handler(buffer -> {
            try {
                chunkConsumer.accept(buffer);
            } catch (final Throwable t) {
                vcf.completeExceptionally(t);
            }
        });
        resp.endHandler(v -> {
            chunkConsumer.accept(null);
            vcf.complete(null);
        });
    }).exceptionHandler(vcf::completeExceptionally);
    httpClientRequest.putHeader("Accept", mediaType);
    credentials.ifPresent(basicCredentials -> httpClientRequest.putHeader("Authorization", createBasicAuthHeader(basicCredentials)));
    Buffer bodyBuffer = Buffer.buffer(bytes);
    httpClientRequest.end(bodyBuffer);
    // cleanup
    vcf.handle((v, throwable) -> {
        httpClient.close();
        vertx.close();
        return null;
    });
    return vcf;
}
Also used : WebClientOptions(io.vertx.ext.web.client.WebClientOptions) VertxCompletableFuture(io.confluent.ksql.util.VertxCompletableFuture) MultiMap(io.vertx.core.MultiMap) CommandStatuses(io.confluent.ksql.rest.entity.CommandStatuses) RestResponse(io.confluent.ksql.rest.client.RestResponse) KsqlErrorMessage(io.confluent.ksql.rest.entity.KsqlErrorMessage) HttpVersion(io.vertx.core.http.HttpVersion) ACCEPT(io.netty.handler.codec.http.HttpHeaderNames.ACCEPT) Map(java.util.Map) URI(java.net.URI) KsqlRequestConfig(io.confluent.ksql.util.KsqlRequestConfig) CommandStatus(io.confluent.ksql.rest.entity.CommandStatus) ImmutableMap(com.google.common.collect.ImmutableMap) TestKsqlRestApp(io.confluent.ksql.rest.server.TestKsqlRestApp) UrlEscapers(com.google.common.net.UrlEscapers) ApiJsonMapper(io.confluent.ksql.rest.ApiJsonMapper) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) Base64(java.util.Base64) List(java.util.List) Buffer(io.vertx.core.buffer.Buffer) Status(io.confluent.ksql.rest.entity.CommandStatus.Status) Optional(java.util.Optional) CONTENT_TYPE(io.netty.handler.codec.http.HttpHeaderNames.CONTENT_TYPE) KsqlRequest(io.confluent.ksql.rest.entity.KsqlRequest) AUTHORIZATION(io.netty.handler.codec.http.HttpHeaderNames.AUTHORIZATION) HttpClient(io.vertx.core.http.HttpClient) HttpResponse(io.vertx.ext.web.client.HttpResponse) StreamedRow(io.confluent.ksql.rest.entity.StreamedRow) WebClient(io.vertx.ext.web.client.WebClient) POST(io.vertx.core.http.HttpMethod.POST) BodyCodec(io.vertx.ext.web.codec.BodyCodec) KsqlEntityList(io.confluent.ksql.rest.entity.KsqlEntityList) CompletableFuture(java.util.concurrent.CompletableFuture) WebsocketVersion(io.vertx.core.http.WebsocketVersion) ServerClusterId(io.confluent.ksql.rest.entity.ServerClusterId) ArrayList(java.util.ArrayList) KsqlEntity(io.confluent.ksql.rest.entity.KsqlEntity) HttpClientRequest(io.vertx.core.http.HttpClientRequest) ServerInfo(io.confluent.ksql.rest.entity.ServerInfo) KsqlRestClient(io.confluent.ksql.rest.client.KsqlRestClient) Charset(java.nio.charset.Charset) WriteStream(io.vertx.core.streams.WriteStream) HttpClientOptions(io.vertx.core.http.HttpClientOptions) TestDataProvider(io.confluent.ksql.util.TestDataProvider) HTTP_1_1(io.vertx.core.http.HttpVersion.HTTP_1_1) Credentials(io.confluent.ksql.test.util.secure.Credentials) Vertx(io.vertx.core.Vertx) CommandStatusEntity(io.confluent.ksql.rest.entity.CommandStatusEntity) BasicCredentials(io.confluent.ksql.rest.client.BasicCredentials) ServerMetadata(io.confluent.ksql.rest.entity.ServerMetadata) KsqlMediaType(io.confluent.ksql.rest.entity.KsqlMediaType) HttpRequest(io.vertx.ext.web.client.HttpRequest) Consumer(java.util.function.Consumer) HttpMethod(io.vertx.core.http.HttpMethod) HealthCheckResponse(io.confluent.ksql.rest.entity.HealthCheckResponse) Collections(java.util.Collections) Buffer(io.vertx.core.buffer.Buffer) VertxCompletableFuture(io.confluent.ksql.util.VertxCompletableFuture) Vertx(io.vertx.core.Vertx) HttpClientOptions(io.vertx.core.http.HttpClientOptions) HttpClientRequest(io.vertx.core.http.HttpClientRequest) HttpClient(io.vertx.core.http.HttpClient)

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 KsqlEntity (io.confluent.ksql.rest.entity.KsqlEntity)2 StreamedRow (io.confluent.ksql.rest.entity.StreamedRow)2 TestKsqlRestApp (io.confluent.ksql.rest.server.TestKsqlRestApp)2 KsqlRequestConfig (io.confluent.ksql.util.KsqlRequestConfig)2 UrlEscapers (com.google.common.net.UrlEscapers)1 ApiJsonMapper (io.confluent.ksql.rest.ApiJsonMapper)1 ClusterStatusResponse (io.confluent.ksql.rest.entity.ClusterStatusResponse)1 CommandStatus (io.confluent.ksql.rest.entity.CommandStatus)1 Status (io.confluent.ksql.rest.entity.CommandStatus.Status)1 CommandStatusEntity (io.confluent.ksql.rest.entity.CommandStatusEntity)1 CommandStatuses (io.confluent.ksql.rest.entity.CommandStatuses)1 HealthCheckResponse (io.confluent.ksql.rest.entity.HealthCheckResponse)1 HeartbeatResponse (io.confluent.ksql.rest.entity.HeartbeatResponse)1 HostStatusEntity (io.confluent.ksql.rest.entity.HostStatusEntity)1 KsqlEntityList (io.confluent.ksql.rest.entity.KsqlEntityList)1 KsqlErrorMessage (io.confluent.ksql.rest.entity.KsqlErrorMessage)1