Search in sources :

Example 11 with KsqlRestClientException

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

the class ListQueriesExecutorTest method shouldIncludeUnresponsiveIfShowQueriesFutureThrowsException.

@Test
public void shouldIncludeUnresponsiveIfShowQueriesFutureThrowsException() {
    // Given
    when(sessionProperties.getInternalRequest()).thenReturn(false);
    final ConfiguredStatement<ListQueries> showQueries = (ConfiguredStatement<ListQueries>) engine.configure("SHOW QUERIES;");
    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(ksqlClient.makeKsqlRequest(any(), any(), any())).thenThrow(new KsqlRestClientException("error"));
    when(serviceContext.getKsqlClient()).thenReturn(ksqlClient);
    queryStatusCount.updateStatusCount(RUNNING_QUERY_STATE, 1);
    queryStatusCount.updateStatusCount(KsqlQueryStatus.UNRESPONSIVE, 1);
    // When
    final Queries queries = (Queries) CUSTOM_EXECUTORS.listQueries().execute(showQueries, sessionProperties, engine, serviceContext).getEntity().orElseThrow(IllegalStateException::new);
    // Then
    assertThat(queries.getQueries(), containsInAnyOrder(persistentQueryMetadataToRunningQuery(metadata, queryStatusCount)));
}
Also used : ConfiguredStatement(io.confluent.ksql.statement.ConfiguredStatement) KsqlEngine(io.confluent.ksql.engine.KsqlEngine) Queries(io.confluent.ksql.rest.entity.Queries) ListQueries(io.confluent.ksql.parser.tree.ListQueries) KsqlRestClientException(io.confluent.ksql.rest.client.exception.KsqlRestClientException) ListQueries(io.confluent.ksql.parser.tree.ListQueries) PersistentQueryMetadata(io.confluent.ksql.util.PersistentQueryMetadata) Test(org.junit.Test)

Example 12 with KsqlRestClientException

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

the class ListQueriesExecutorTest method shouldIncludeUnresponsiveIfShowQueriesExtendedFutureThrowsException.

@Test
public void shouldIncludeUnresponsiveIfShowQueriesExtendedFutureThrowsException() {
    // 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(ksqlClient.makeKsqlRequest(any(), any(), any())).thenThrow(new KsqlRestClientException("error"));
    when(serviceContext.getKsqlClient()).thenReturn(ksqlClient);
    // When
    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) KsqlRestClientException(io.confluent.ksql.rest.client.exception.KsqlRestClientException) 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) KsqlQueryStatus(io.confluent.ksql.util.KsqlConstants.KsqlQueryStatus) Test(org.junit.Test)

Example 13 with KsqlRestClientException

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

the class KsqlClient method createHttpClient.

private static HttpClient createHttpClient(final Vertx vertx, final Map<String, String> clientProps, final HttpClientOptions httpClientOptions, final boolean tls) {
    if (tls) {
        httpClientOptions.setSsl(true);
        configureHostVerification(clientProps, httpClientOptions);
        final Optional<JksOptions> trustStoreOptions = VertxSslOptionsFactory.getJksTrustStoreOptions(clientProps);
        if (trustStoreOptions.isPresent()) {
            httpClientOptions.setTrustStoreOptions(trustStoreOptions.get());
            final String alias = clientProps.get(SSL_KEYSTORE_ALIAS_CONFIG);
            final Optional<JksOptions> keyStoreOptions = VertxSslOptionsFactory.buildJksKeyStoreOptions(clientProps, Optional.ofNullable(alias));
            keyStoreOptions.ifPresent(options -> httpClientOptions.setKeyStoreOptions(options));
        }
    }
    try {
        return vertx.createHttpClient(httpClientOptions);
    } catch (VertxException e) {
        throw new KsqlRestClientException(e.getMessage(), e);
    }
}
Also used : KsqlRestClientException(io.confluent.ksql.rest.client.exception.KsqlRestClientException) VertxException(io.vertx.core.VertxException) JksOptions(io.vertx.core.net.JksOptions)

Example 14 with KsqlRestClientException

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

the class CliTest method shouldPrintErrorIfCantConnectToRestServerOnRunCommand.

@Test
public void shouldPrintErrorIfCantConnectToRestServerOnRunCommand() throws Exception {
    givenRunInteractivelyWillExit();
    final KsqlRestClient mockRestClient = givenMockRestClient();
    when(mockRestClient.getServerInfo()).thenThrow(new KsqlRestClientException("Boom", new IOException("")));
    new Cli(1L, 1L, mockRestClient, console).runCommand("this is a command");
    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 15 with KsqlRestClientException

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

the class RemoteServerSpecificCommandTest method shouldPrintErrorWhenCantConnectToNewAddress.

@Test
public void shouldPrintErrorWhenCantConnectToNewAddress() {
    // Given:
    when(restClient.getServerInfo()).thenThrow(new KsqlRestClientException("Failed to connect", new IOException("Boom")));
    // When:
    command.execute(ImmutableList.of(VALID_SERVER_ADDRESS), terminal);
    // Then:
    assertThat(out.toString(), containsString("Boom"));
    assertThat(out.toString(), containsString("Failed to connect"));
}
Also used : KsqlRestClientException(io.confluent.ksql.rest.client.exception.KsqlRestClientException) IOException(java.io.IOException) Test(org.junit.Test)

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