Search in sources :

Example 1 with KsqlApiException

use of io.confluent.ksql.api.server.KsqlApiException in project ksql by confluentinc.

the class ClientTest method shouldHandleErrorResponseFromStreamInserts.

@Test
public void shouldHandleErrorResponseFromStreamInserts() {
    // Given
    KsqlApiException exception = new KsqlApiException("Invalid target name", ERROR_CODE_BAD_STATEMENT);
    testEndpoints.setCreateInsertsSubscriberException(exception);
    // When
    final Exception e = assertThrows(// thrown from .get() when the future completes exceptionally
    ExecutionException.class, () -> javaClient.streamInserts("a-table", new InsertsPublisher()).get());
    // Then
    assertThat(e.getCause(), instanceOf(KsqlClientException.class));
    assertThat(e.getCause().getMessage(), containsString("Received 400 response from server"));
    assertThat(e.getCause().getMessage(), containsString("Invalid target name"));
}
Also used : KsqlClientException(io.confluent.ksql.api.client.exception.KsqlClientException) KsqlApiException(io.confluent.ksql.api.server.KsqlApiException) KafkaResponseGetFailedException(io.confluent.ksql.exception.KafkaResponseGetFailedException) KsqlClientException(io.confluent.ksql.api.client.exception.KsqlClientException) KsqlApiException(io.confluent.ksql.api.server.KsqlApiException) ExecutionException(java.util.concurrent.ExecutionException) ParseFailedException(io.confluent.ksql.parser.exception.ParseFailedException) KsqlException(io.confluent.ksql.api.client.exception.KsqlException) BaseApiTest(io.confluent.ksql.api.BaseApiTest) Test(org.junit.Test)

Example 2 with KsqlApiException

use of io.confluent.ksql.api.server.KsqlApiException in project ksql by confluentinc.

the class ClientTest method shouldHandleErrorResponseFromInsertInto.

@Test
public void shouldHandleErrorResponseFromInsertInto() {
    // Given
    KsqlApiException exception = new KsqlApiException("Invalid target name", ERROR_CODE_BAD_STATEMENT);
    testEndpoints.setCreateInsertsSubscriberException(exception);
    // When
    final Exception e = assertThrows(// thrown from .get() when the future completes exceptionally
    ExecutionException.class, () -> javaClient.insertInto("a-table", INSERT_ROWS.get(0)).get());
    // Then
    assertThat(e.getCause(), instanceOf(KsqlClientException.class));
    assertThat(e.getCause().getMessage(), containsString("Received 400 response from server"));
    assertThat(e.getCause().getMessage(), containsString("Invalid target name"));
}
Also used : KsqlClientException(io.confluent.ksql.api.client.exception.KsqlClientException) KsqlApiException(io.confluent.ksql.api.server.KsqlApiException) KafkaResponseGetFailedException(io.confluent.ksql.exception.KafkaResponseGetFailedException) KsqlClientException(io.confluent.ksql.api.client.exception.KsqlClientException) KsqlApiException(io.confluent.ksql.api.server.KsqlApiException) ExecutionException(java.util.concurrent.ExecutionException) ParseFailedException(io.confluent.ksql.parser.exception.ParseFailedException) KsqlException(io.confluent.ksql.api.client.exception.KsqlException) BaseApiTest(io.confluent.ksql.api.BaseApiTest) Test(org.junit.Test)

Example 3 with KsqlApiException

use of io.confluent.ksql.api.server.KsqlApiException in project ksql by confluentinc.

the class InsertsStreamEndpoint method createInsertsSubscriber.

public InsertsStreamSubscriber createInsertsSubscriber(final String caseInsensitiveTarget, final JsonObject properties, final Subscriber<InsertResult> acksSubscriber, final Context context, final WorkerExecutor workerExecutor, final ServiceContext serviceContext) {
    VertxUtils.checkIsWorker();
    if (!ksqlConfig.getBoolean(KsqlConfig.KSQL_INSERT_INTO_VALUES_ENABLED)) {
        throw new KsqlApiException("The server has disabled INSERT INTO ... VALUES functionality. " + "To enable it, restart your ksqlDB server " + "with 'ksql.insert.into.values.enabled'=true", ERROR_CODE_BAD_REQUEST);
    }
    final String target;
    try {
        target = Identifiers.getIdentifierText(caseInsensitiveTarget);
    } catch (IllegalArgumentException e) {
        throw new KsqlApiException("Invalid target name: " + e.getMessage(), ERROR_CODE_BAD_STATEMENT);
    }
    final DataSource dataSource = getDataSource(ksqlEngine.getMetaStore(), SourceName.of(target));
    return InsertsSubscriber.createInsertsSubscriber(serviceContext, properties, dataSource, ksqlConfig, context, acksSubscriber, workerExecutor);
}
Also used : KsqlApiException(io.confluent.ksql.api.server.KsqlApiException) DataSource(io.confluent.ksql.metastore.model.DataSource)

Example 4 with KsqlApiException

use of io.confluent.ksql.api.server.KsqlApiException in project ksql by confluentinc.

the class KeyValueExtractor method extractKey.

public static GenericKey extractKey(final JsonObject values, final LogicalSchema logicalSchema, final SqlValueCoercer sqlValueCoercer) {
    final List<Column> keyColumns = logicalSchema.key();
    final GenericKey.Builder builder = GenericKey.builder(logicalSchema);
    for (final Column keyColumn : keyColumns) {
        final Object value = values.getValue(keyColumn.name().text());
        if (value == null) {
            throw new KsqlApiException("Key field must be specified: " + keyColumn.name().text(), Errors.ERROR_CODE_BAD_REQUEST);
        }
        final Object coercedValue = coerceObject(value, keyColumn.type(), sqlValueCoercer);
        builder.append(coercedValue);
    }
    return builder.build();
}
Also used : Column(io.confluent.ksql.schema.ksql.Column) JsonObject(io.vertx.core.json.JsonObject) GenericKey(io.confluent.ksql.GenericKey) KsqlApiException(io.confluent.ksql.api.server.KsqlApiException)

Example 5 with KsqlApiException

use of io.confluent.ksql.api.server.KsqlApiException in project ksql by confluentinc.

the class AuthTest method setupSecurityPlugin.

private void setupSecurityPlugin(final String expectedUser, final ExceptionThrowingRunnable action, final boolean authenticate, final boolean shouldCallHandler, final boolean enableBasicAuth) throws Exception {
    stopServer();
    stopClient();
    final AtomicBoolean handlerCalled = new AtomicBoolean();
    this.securityHandlerPlugin = new AuthenticationPlugin() {

        @Override
        public void configure(final Map<String, ?> map) {
        }

        @Override
        public CompletableFuture<Principal> handleAuth(final RoutingContext routingContext, final WorkerExecutor workerExecutor) {
            handlerCalled.set(true);
            if (authenticate) {
                return CompletableFuture.completedFuture(new StringPrincipal(expectedUser));
            } else {
                routingContext.fail(401, new KsqlApiException("Unauthorized", ERROR_CODE_UNAUTHORIZED));
                return CompletableFuture.completedFuture(null);
            }
        }
    };
    KsqlRestConfig KsqlRestConfig = enableBasicAuth ? createServerConfig() : createServerConfigNoBasicAuth();
    createServer(KsqlRestConfig);
    client = createClient();
    action.run();
    assertThat(handlerCalled.get(), is(shouldCallHandler));
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) RoutingContext(io.vertx.ext.web.RoutingContext) VertxCompletableFuture(io.confluent.ksql.util.VertxCompletableFuture) CompletableFuture(java.util.concurrent.CompletableFuture) WorkerExecutor(io.vertx.core.WorkerExecutor) KsqlRestConfig(io.confluent.ksql.rest.server.KsqlRestConfig) AuthenticationPlugin(io.confluent.ksql.api.auth.AuthenticationPlugin) KsqlApiException(io.confluent.ksql.api.server.KsqlApiException)

Aggregations

KsqlApiException (io.confluent.ksql.api.server.KsqlApiException)5 BaseApiTest (io.confluent.ksql.api.BaseApiTest)2 KsqlClientException (io.confluent.ksql.api.client.exception.KsqlClientException)2 KsqlException (io.confluent.ksql.api.client.exception.KsqlException)2 KafkaResponseGetFailedException (io.confluent.ksql.exception.KafkaResponseGetFailedException)2 ParseFailedException (io.confluent.ksql.parser.exception.ParseFailedException)2 ExecutionException (java.util.concurrent.ExecutionException)2 Test (org.junit.Test)2 GenericKey (io.confluent.ksql.GenericKey)1 AuthenticationPlugin (io.confluent.ksql.api.auth.AuthenticationPlugin)1 DataSource (io.confluent.ksql.metastore.model.DataSource)1 KsqlRestConfig (io.confluent.ksql.rest.server.KsqlRestConfig)1 Column (io.confluent.ksql.schema.ksql.Column)1 VertxCompletableFuture (io.confluent.ksql.util.VertxCompletableFuture)1 WorkerExecutor (io.vertx.core.WorkerExecutor)1 JsonObject (io.vertx.core.json.JsonObject)1 RoutingContext (io.vertx.ext.web.RoutingContext)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1