Search in sources :

Example 6 with KsqlRestClientException

use of io.confluent.ksql.rest.client.exception.KsqlRestClientException in project ksql by confluentinc.

the class KsqlClientTest method shouldFailToStartClientRequestWithNullKeystorePassword.

@Test
public void shouldFailToStartClientRequestWithNullKeystorePassword() throws Exception {
    ksqlClient.close();
    stopServer();
    // Given:
    startServerWithTls();
    // When:
    final KsqlRestClientException e = assertThrows(KsqlRestClientException.class, () -> startClientWithTlsAndTruststorePassword(null));
    // Then:
    assertThat(e.getMessage(), containsString("java.io.IOException: Keystore was tampered with, or password was incorrect"));
}
Also used : KsqlRestClientException(io.confluent.ksql.rest.client.exception.KsqlRestClientException) Test(org.junit.Test)

Example 7 with KsqlRestClientException

use of io.confluent.ksql.rest.client.exception.KsqlRestClientException in project ksql by confluentinc.

the class KsqlTarget method executeRequestSync.

private <R, T> RestResponse<R> executeRequestSync(final HttpMethod httpMethod, final String path, final Object requestBody, final Supplier<R> responseSupplier, final Function<Buffer, T> chunkMapper, final String delimiter, final Consumer<T> chunkHandler, final CompletableFuture<Void> shouldCloseConnection) {
    return executeSync(httpMethod, path, Optional.empty(), requestBody, resp -> responseSupplier.get(), (resp, vcf) -> {
        final RecordParser recordParser = RecordParser.newDelimited(delimiter, resp);
        final AtomicBoolean end = new AtomicBoolean(false);
        recordParser.exceptionHandler(vcf::completeExceptionally);
        recordParser.handler(buff -> {
            try {
                chunkHandler.accept(chunkMapper.apply(buff));
            } catch (Throwable t) {
                log.error("Error while handling chunk", t);
                vcf.completeExceptionally(t);
            }
        });
        recordParser.endHandler(v -> {
            try {
                end.set(true);
                chunkHandler.accept(null);
                vcf.complete(new ResponseWithBody(resp, Buffer.buffer()));
            } catch (Throwable t) {
                log.error("Error while handling end", t);
                vcf.completeExceptionally(t);
            }
        });
        // Closing after the end handle was called resulted in errors about the connection being
        // closed, so we even turn this on the context so there's no race.
        final Context context = Vertx.currentContext();
        shouldCloseConnection.handle((v, t) -> {
            context.runOnContext(v2 -> {
                if (!end.get()) {
                    try {
                        resp.request().connection().close();
                        vcf.completeExceptionally(new KsqlRestClientException("Closing connection"));
                    } catch (Throwable closing) {
                        log.error("Error while handling close", closing);
                        vcf.completeExceptionally(closing);
                    }
                }
            });
            return null;
        });
    });
}
Also used : Context(io.vertx.core.Context) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) KsqlRestClientException(io.confluent.ksql.rest.client.exception.KsqlRestClientException) RecordParser(io.vertx.core.parsetools.RecordParser)

Example 8 with KsqlRestClientException

use of io.confluent.ksql.rest.client.exception.KsqlRestClientException in project ksql by confluentinc.

the class KsqlTarget method executeSync.

private <T> RestResponse<T> executeSync(final HttpMethod httpMethod, final String path, final Optional<String> mediaType, final Object requestBody, final Function<ResponseWithBody, T> mapper, final BiConsumer<HttpClientResponse, CompletableFuture<ResponseWithBody>> responseHandler) {
    final CompletableFuture<ResponseWithBody> vcf = execute(httpMethod, path, mediaType, requestBody, responseHandler);
    final ResponseWithBody response;
    try {
        response = vcf.get();
    } catch (Exception e) {
        throw new KsqlRestClientException("Error issuing " + httpMethod + " to KSQL server. path:" + path, e);
    }
    return KsqlClientUtil.toRestResponse(response, path, mapper);
}
Also used : KsqlRestClientException(io.confluent.ksql.rest.client.exception.KsqlRestClientException) KsqlRestClientException(io.confluent.ksql.rest.client.exception.KsqlRestClientException)

Example 9 with KsqlRestClientException

use of io.confluent.ksql.rest.client.exception.KsqlRestClientException in project ksql by confluentinc.

the class CliTest method shouldPrintErrorIfCantConnectToRestServerOnRunInteractively.

@Test
public void shouldPrintErrorIfCantConnectToRestServerOnRunInteractively() throws Exception {
    givenRunInteractivelyWillExit();
    final KsqlRestClient mockRestClient = givenMockRestClient();
    when(mockRestClient.getServerInfo()).thenThrow(new KsqlRestClientException("Boom", new IOException("")));
    new Cli(1L, 1L, mockRestClient, console).runInteractively();
    assertThat(terminal.getOutputString(), containsString("Please ensure that the URL provided is for an active KSQL server."));
}
Also used : KsqlRestClient(io.confluent.ksql.rest.client.KsqlRestClient) KsqlRestClientException(io.confluent.ksql.rest.client.exception.KsqlRestClientException) IOException(java.io.IOException) Test(org.junit.Test) IntegrationTest(io.confluent.common.utils.IntegrationTest)

Example 10 with KsqlRestClientException

use of io.confluent.ksql.rest.client.exception.KsqlRestClientException in project ksql by confluentinc.

the class CliTest method shouldPrintErrorIfCantConnectToRestServerOnRunScript.

@Test
public void shouldPrintErrorIfCantConnectToRestServerOnRunScript() throws Exception {
    // Given
    final KsqlRestClient mockRestClient = givenMockRestClient();
    when(mockRestClient.getServerInfo()).thenThrow(new KsqlRestClientException("Boom", new IOException("")));
    new Cli(1L, 1L, mockRestClient, console).runScript("script_file_ignored");
    assertThat(terminal.getOutputString(), containsString("Please ensure that the URL provided is for an active KSQL server."));
}
Also used : KsqlRestClient(io.confluent.ksql.rest.client.KsqlRestClient) KsqlRestClientException(io.confluent.ksql.rest.client.exception.KsqlRestClientException) IOException(java.io.IOException) Test(org.junit.Test) IntegrationTest(io.confluent.common.utils.IntegrationTest)

Aggregations

KsqlRestClientException (io.confluent.ksql.rest.client.exception.KsqlRestClientException)16 Test (org.junit.Test)12 IOException (java.io.IOException)4 IntegrationTest (io.confluent.common.utils.IntegrationTest)3 KsqlRestClient (io.confluent.ksql.rest.client.KsqlRestClient)3 KsqlEngine (io.confluent.ksql.engine.KsqlEngine)2 ListQueries (io.confluent.ksql.parser.tree.ListQueries)2 ConfiguredStatement (io.confluent.ksql.statement.ConfiguredStatement)2 PersistentQueryMetadata (io.confluent.ksql.util.PersistentQueryMetadata)2 URI (java.net.URI)2 KsqlErrorMessage (io.confluent.ksql.rest.entity.KsqlErrorMessage)1 KsqlHostInfoEntity (io.confluent.ksql.rest.entity.KsqlHostInfoEntity)1 Queries (io.confluent.ksql.rest.entity.Queries)1 QueryDescriptionList (io.confluent.ksql.rest.entity.QueryDescriptionList)1 ServerInfo (io.confluent.ksql.rest.entity.ServerInfo)1 DiscoverRemoteHostsUtil (io.confluent.ksql.rest.util.DiscoverRemoteHostsUtil)1 KsqlQueryStatus (io.confluent.ksql.util.KsqlConstants.KsqlQueryStatus)1 Context (io.vertx.core.Context)1 VertxException (io.vertx.core.VertxException)1 JksOptions (io.vertx.core.net.JksOptions)1