use of io.confluent.ksql.util.VertxCompletableFuture in project ksql by confluentinc.
the class PullQueryRunner method run.
@Override
protected void run(long runMs) throws Exception {
Semaphore sem = new Semaphore(MAX_CONCURRENT_REQUESTS);
long start = System.currentTimeMillis();
do {
sem.acquire();
VertxCompletableFuture<HttpResponse<Buffer>> vcf = new VertxCompletableFuture<>();
client.post(8089, "localhost", "/query-stream").sendJsonObject(DEFAULT_PULL_QUERY_REQUEST_BODY, vcf);
vcf.thenAccept(resp -> {
count();
sem.release();
});
} while (System.currentTimeMillis() - start < runMs);
}
use of io.confluent.ksql.util.VertxCompletableFuture in project ksql by confluentinc.
the class TlsTest method shouldFailToUseDisabledTlsVersion.
@Test
public void shouldFailToUseDisabledTlsVersion() {
// Given
WebClientOptions clientOptions = createClientOptions().setEnabledSecureTransportProtocols(Collections.singleton("TLSv1.1"));
WebClient client = WebClient.create(vertx, clientOptions);
// When
JsonObject requestBody = new JsonObject().put("ksql", "show streams;");
VertxCompletableFuture<HttpResponse<Buffer>> requestFuture = new VertxCompletableFuture<>();
client.post("/ksql").sendBuffer(requestBody.toBuffer(), requestFuture);
// Then
try {
requestFuture.get();
} catch (Exception e) {
assertThat(e, // thrown from CompletableFuture.get()
instanceOf(ExecutionException.class));
assertThat(e.getMessage(), containsString("javax.net.ssl.SSLHandshakeException: Failed to create SSL connection"));
}
}
use of io.confluent.ksql.util.VertxCompletableFuture in project ksql by confluentinc.
the class KsqlTarget method execute.
private CompletableFuture<ResponseWithBody> execute(final HttpMethod httpMethod, final String path, final Optional<String> mediaType, final Object requestBody, final BiConsumer<HttpClientResponse, CompletableFuture<ResponseWithBody>> responseHandler) {
final VertxCompletableFuture<ResponseWithBody> vcf = new VertxCompletableFuture<>();
final HttpClientRequest httpClientRequest = httpClient.request(httpMethod, socketAddress, socketAddress.port(), host, path, resp -> responseHandler.accept(resp, vcf)).exceptionHandler(vcf::completeExceptionally);
if (mediaType.isPresent()) {
httpClientRequest.putHeader("Accept", mediaType.get());
} else {
httpClientRequest.putHeader("Accept", "application/json");
}
authHeader.ifPresent(v -> httpClientRequest.putHeader("Authorization", v));
additionalHeaders.forEach(httpClientRequest::putHeader);
if (requestBody != null) {
httpClientRequest.end(serialize(requestBody));
} else {
httpClientRequest.end();
}
return vcf;
}
use of io.confluent.ksql.util.VertxCompletableFuture in project ksql by confluentinc.
the class Server method start.
public synchronized void start() {
if (!deploymentIds.isEmpty()) {
throw new IllegalStateException("Already started");
}
final int idleConnectionTimeoutSeconds = config.getInt(KsqlRestConfig.IDLE_CONNECTION_TIMEOUT_SECONDS);
this.workerExecutor = vertx.createSharedWorkerExecutor("ksql-workers", config.getInt(KsqlRestConfig.WORKER_POOL_SIZE));
final LoggingRateLimiter loggingRateLimiter = new LoggingRateLimiter(config);
configureTlsCertReload(config);
final List<URI> listenUris = parseListeners(config);
final Optional<URI> internalListenUri = parseInternalListener(config, listenUris);
final List<URI> allListenUris = new ArrayList<>(listenUris);
internalListenUri.ifPresent(allListenUris::add);
final int instances = config.getInt(KsqlRestConfig.VERTICLE_INSTANCES);
log.debug("Deploying " + instances + " instances of server verticle");
final List<CompletableFuture<String>> deployFutures = new ArrayList<>();
final Map<URI, URI> uris = new ConcurrentHashMap<>();
for (URI listener : allListenUris) {
final Optional<Boolean> isInternalListener = internalListenUri.map(uri -> uri.equals(listener));
for (int i = 0; i < instances; i++) {
final VertxCompletableFuture<String> vcf = new VertxCompletableFuture<>();
final ServerVerticle serverVerticle = new ServerVerticle(endpoints, createHttpServerOptions(config, listener.getHost(), listener.getPort(), listener.getScheme().equalsIgnoreCase("https"), isInternalListener.orElse(false), idleConnectionTimeoutSeconds), this, isInternalListener, loggingRateLimiter);
vertx.deployVerticle(serverVerticle, vcf);
final int index = i;
final CompletableFuture<String> deployFuture = vcf.thenApply(s -> {
if (index == 0) {
try {
final URI uriWithPort = new URI(listener.getScheme(), null, listener.getHost(), serverVerticle.actualPort(), null, null, null);
uris.put(listener, uriWithPort);
} catch (URISyntaxException e) {
throw new KsqlException(e);
}
}
return s;
});
deployFutures.add(deployFuture);
}
}
final CompletableFuture<Void> allDeployFuture = CompletableFuture.allOf(deployFutures.toArray(new CompletableFuture<?>[0]));
try {
allDeployFuture.get();
for (CompletableFuture<String> deployFuture : deployFutures) {
deploymentIds.add(deployFuture.get());
}
} catch (Exception e) {
throw new KsqlException("Failed to start API server", e);
}
for (URI uri : listenUris) {
listeners.add(uris.get(uri));
}
if (internalListenUri.isPresent()) {
internalListener = uris.get(internalListenUri.get());
}
log.info("API server started");
}
use of io.confluent.ksql.util.VertxCompletableFuture in project ksql by confluentinc.
the class Server method stop.
public synchronized void stop() {
if (deploymentIds.isEmpty()) {
throw new IllegalStateException("Not started");
}
if (workerExecutor != null) {
workerExecutor.close();
}
if (fileWatcher != null) {
fileWatcher.shutdown();
}
final List<CompletableFuture<Void>> undeployFutures = new ArrayList<>();
for (String deploymentID : deploymentIds) {
final VertxCompletableFuture<Void> future = new VertxCompletableFuture<>();
vertx.undeploy(deploymentID, future);
undeployFutures.add(future);
}
try {
CompletableFuture.allOf(undeployFutures.toArray(new CompletableFuture<?>[0])).get();
} catch (Exception e) {
throw new KsqlException("Failure in stopping API server", e);
}
deploymentIds.clear();
listeners.clear();
log.info("API server stopped");
}
Aggregations