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"));
}
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));
}
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"));
}
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"));
}
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();
}
}
Aggregations