Search in sources :

Example 11 with KsqlErrorMessage

use of io.confluent.ksql.rest.entity.KsqlErrorMessage in project ksql by confluentinc.

the class KsqlResourceTest method shouldReturn5xxOnStatementSystemError.

@Test
public void shouldReturn5xxOnStatementSystemError() {
    // Given:
    final String ksqlString = "CREATE STREAM test_explain AS SELECT * FROM test_stream;";
    givenMockEngine();
    reset(sandbox);
    when(sandbox.getMetaStore()).thenReturn(metaStore);
    when(sandbox.prepare(any(), any())).thenAnswer(invocation -> realEngine.createSandbox(serviceContext).prepare(invocation.getArgument(0), Collections.emptyMap()));
    when(sandbox.plan(any(), any(ConfiguredStatement.class))).thenThrow(new RuntimeException("internal error"));
    when(sandbox.getKsqlConfig()).thenReturn(ksqlConfig);
    // When:
    final KsqlErrorMessage result = makeFailingRequest(ksqlString, INTERNAL_SERVER_ERROR.code());
    // Then:
    assertThat(result.getErrorCode(), is(Errors.ERROR_CODE_SERVER_ERROR));
    assertThat(result.getMessage(), containsString("internal error"));
}
Also used : ConfiguredStatement(io.confluent.ksql.statement.ConfiguredStatement) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) KsqlErrorMessage(io.confluent.ksql.rest.entity.KsqlErrorMessage) Test(org.junit.Test)

Example 12 with KsqlErrorMessage

use of io.confluent.ksql.rest.entity.KsqlErrorMessage in project ksql by confluentinc.

the class KsqlResourceTest method shouldReturnForbiddenKafkaAccessIfKsqlTopicAuthorizationException.

@Test
public void shouldReturnForbiddenKafkaAccessIfKsqlTopicAuthorizationException() {
    // Given:
    final String errorMsg = "some error";
    when(errorsHandler.generateResponse(any(), any())).thenReturn(EndpointResponse.create().status(FORBIDDEN.code()).entity(new KsqlErrorMessage(ERROR_CODE_FORBIDDEN_KAFKA_ACCESS, errorMsg)).build());
    doThrow(new KsqlTopicAuthorizationException(AclOperation.DELETE, Collections.singleton("topic"))).when(authorizationValidator).checkAuthorization(any(), any(), any());
    // When:
    final KsqlErrorMessage result = makeFailingRequest("DROP STREAM TEST_STREAM DELETE TOPIC;", FORBIDDEN.code());
    // Then:
    assertThat(result, is(instanceOf(KsqlErrorMessage.class)));
    assertThat(result.getErrorCode(), is(Errors.ERROR_CODE_FORBIDDEN_KAFKA_ACCESS));
    assertThat(result.getMessage(), is(errorMsg));
}
Also used : KsqlTopicAuthorizationException(io.confluent.ksql.exception.KsqlTopicAuthorizationException) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) KsqlErrorMessage(io.confluent.ksql.rest.entity.KsqlErrorMessage) Test(org.junit.Test)

Example 13 with KsqlErrorMessage

use of io.confluent.ksql.rest.entity.KsqlErrorMessage in project ksql by confluentinc.

the class KsqlResourceTest method shouldFailSetPropertyOnInvalidPropertyValue.

@Test
public void shouldFailSetPropertyOnInvalidPropertyValue() {
    // When:
    final KsqlErrorMessage response = makeFailingRequest("SET '" + ConsumerConfig.AUTO_OFFSET_RESET_CONFIG + "' = 'invalid value';", BAD_REQUEST.code());
    // Then:
    assertThat(response, instanceOf(KsqlStatementErrorMessage.class));
    assertThat(response.getErrorCode(), is(Errors.ERROR_CODE_BAD_STATEMENT));
    assertThat(response.getMessage(), containsString("Invalid value invalid value for configuration auto.offset.reset: " + "String must be one of: latest, earliest, none"));
}
Also used : KsqlStatementErrorMessage(io.confluent.ksql.rest.entity.KsqlStatementErrorMessage) KsqlErrorMessage(io.confluent.ksql.rest.entity.KsqlErrorMessage) Test(org.junit.Test)

Example 14 with KsqlErrorMessage

use of io.confluent.ksql.rest.entity.KsqlErrorMessage in project ksql by confluentinc.

the class KsqlResourceTest method shouldReturnServiceUnavailableIfTimeoutWaitingForCommandSequenceNumber.

@Test
public void shouldReturnServiceUnavailableIfTimeoutWaitingForCommandSequenceNumber() throws Exception {
    // Given:
    doThrow(new TimeoutException("timed out!")).when(commandStore).ensureConsumedPast(anyLong(), any());
    // When:
    final KsqlErrorMessage result = makeFailingRequestWithSequenceNumber("list properties;", 2L, SERVICE_UNAVAILABLE.code());
    // Then:
    assertThat(result.getErrorCode(), is(Errors.ERROR_CODE_COMMAND_QUEUE_CATCHUP_TIMEOUT));
    assertThat(result.getMessage(), containsString("Timed out while waiting for a previous command to execute"));
    assertThat(result.getMessage(), containsString("command sequence number: 2"));
}
Also used : KsqlErrorMessage(io.confluent.ksql.rest.entity.KsqlErrorMessage) TimeoutException(java.util.concurrent.TimeoutException) Test(org.junit.Test)

Example 15 with KsqlErrorMessage

use of io.confluent.ksql.rest.entity.KsqlErrorMessage in project ksql by confluentinc.

the class RemoteServerSpecificCommand method validateClient.

public static void validateClient(final PrintWriter writer, final KsqlRestClient restClient) {
    try {
        final RestResponse<ServerInfo> restResponse = restClient.getServerInfo();
        if (restResponse.isErroneous()) {
            final KsqlErrorMessage ksqlError = restResponse.getErrorMessage();
            if (Errors.toStatusCode(ksqlError.getErrorCode()) == NOT_ACCEPTABLE.code()) {
                writer.format("This CLI version no longer supported: %s%n%n", ksqlError);
                return;
            }
            writer.format("Couldn't connect to the KSQL server: %s%n%n", ksqlError.getMessage());
        } else {
            maybeSetIsCCloudServer(restClient, restResponse.getResponse());
        }
    } catch (final IllegalArgumentException exception) {
        writer.println("Server URL must begin with protocol (e.g., http:// or https://)");
    } catch (final KsqlRestClientException exception) {
        writer.println();
        writer.println(StringUtils.center("ERROR", CONSOLE_WIDTH, "*"));
        final String errorMsg;
        if (exception.getCause().getCause() instanceof SSLException) {
            errorMsg = " looks to be configured to use HTTPS / SSL. " + "Please refer to the KSQL documentation on how to configure the CLI for SSL: " + DocumentationLinks.SECURITY_CLI_SSL_DOC_URL;
        } else {
            errorMsg = " does not appear to be a valid KSQL server." + " Please ensure that the URL provided is for an active KSQL server.";
        }
        writer.println(WordUtils.wrap("Remote server at " + restClient.getServerAddress() + errorMsg, CONSOLE_WIDTH));
        writer.println("");
        writer.println("The server responded with the following error: ");
        writer.println(ErrorMessageUtil.buildErrorMessage(exception));
        writer.println(StringUtils.repeat('*', CONSOLE_WIDTH));
        writer.println();
    } finally {
        writer.flush();
    }
}
Also used : KsqlRestClientException(io.confluent.ksql.rest.client.exception.KsqlRestClientException) ServerInfo(io.confluent.ksql.rest.entity.ServerInfo) SSLException(javax.net.ssl.SSLException) KsqlErrorMessage(io.confluent.ksql.rest.entity.KsqlErrorMessage)

Aggregations

KsqlErrorMessage (io.confluent.ksql.rest.entity.KsqlErrorMessage)43 Test (org.junit.Test)35 EndpointResponse (io.confluent.ksql.rest.EndpointResponse)8 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)6 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)6 KsqlEntityList (io.confluent.ksql.rest.entity.KsqlEntityList)5 KsqlStatementErrorMessage (io.confluent.ksql.rest.entity.KsqlStatementErrorMessage)5 IntegrationTest (io.confluent.common.utils.IntegrationTest)4 KsqlTopicAuthorizationException (io.confluent.ksql.exception.KsqlTopicAuthorizationException)4 KsqlEngine (io.confluent.ksql.engine.KsqlEngine)3 KsqlHostInfoEntity (io.confluent.ksql.rest.entity.KsqlHostInfoEntity)3 KsqlRequest (io.confluent.ksql.rest.entity.KsqlRequest)3 ConfiguredStatement (io.confluent.ksql.statement.ConfiguredStatement)3 MetricsCallbackHolder (io.confluent.ksql.api.server.MetricsCallbackHolder)2 ListQueries (io.confluent.ksql.parser.tree.ListQueries)2 Query (io.confluent.ksql.parser.tree.Query)2 KsqlRestClient (io.confluent.ksql.rest.client.KsqlRestClient)2 KsqlConfig (io.confluent.ksql.util.KsqlConfig)2 KsqlStatementException (io.confluent.ksql.util.KsqlStatementException)2 PersistentQueryMetadata (io.confluent.ksql.util.PersistentQueryMetadata)2