Search in sources :

Example 1 with NextHandlerOutput

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

the class StreamedQueryResource method handleStatement.

@SuppressWarnings("unchecked")
private EndpointResponse handleStatement(final KsqlSecurityContext securityContext, final KsqlRequest request, final PreparedStatement<?> statement, final CompletableFuture<Void> connectionClosedFuture, final Optional<Boolean> isInternalRequest, final MetricsCallbackHolder metricsCallbackHolder, final Context context) {
    try {
        authorizationValidator.ifPresent(validator -> validator.checkAuthorization(securityContext, ksqlEngine.getMetaStore(), statement.getStatement()));
        final Map<String, Object> configProperties = request.getConfigOverrides();
        denyListPropertyValidator.validateAll(configProperties);
        if (statement.getStatement() instanceof Query) {
            if (shouldMigrateToQueryStream(request.getConfigOverrides())) {
                return EndpointResponse.ok(new NextHandlerOutput());
            }
            final QueryMetadataHolder queryMetadataHolder = queryExecutor.handleStatement(securityContext.getServiceContext(), request.getConfigOverrides(), request.getRequestProperties(), statement, isInternalRequest, metricsCallbackHolder, context, false);
            return handleQuery((PreparedStatement<Query>) statement, connectionClosedFuture, queryMetadataHolder);
        } else if (statement.getStatement() instanceof PrintTopic) {
            return handlePrintTopic(securityContext.getServiceContext(), configProperties, (PreparedStatement<PrintTopic>) statement, connectionClosedFuture);
        } else {
            return Errors.badRequest(String.format("Statement type `%s' not supported for this resource", statement.getClass().getName()));
        }
    } catch (final TopicAuthorizationException e) {
        return errorHandler.accessDeniedFromKafkaResponse(e);
    } catch (final KsqlStatementException e) {
        return Errors.badStatement(e.getRawMessage(), e.getSqlStatement());
    } catch (final KsqlException e) {
        return errorHandler.generateResponse(e, Errors.badRequest(e));
    }
}
Also used : QueryMetadataHolder(io.confluent.ksql.rest.server.query.QueryMetadataHolder) Query(io.confluent.ksql.parser.tree.Query) PrintTopic(io.confluent.ksql.parser.tree.PrintTopic) PreparedStatement(io.confluent.ksql.parser.KsqlParser.PreparedStatement) KsqlStatementException(io.confluent.ksql.util.KsqlStatementException) KsqlException(io.confluent.ksql.util.KsqlException) TopicAuthorizationException(org.apache.kafka.common.errors.TopicAuthorizationException) NextHandlerOutput(io.confluent.ksql.api.server.NextHandlerOutput)

Aggregations

NextHandlerOutput (io.confluent.ksql.api.server.NextHandlerOutput)1 PreparedStatement (io.confluent.ksql.parser.KsqlParser.PreparedStatement)1 PrintTopic (io.confluent.ksql.parser.tree.PrintTopic)1 Query (io.confluent.ksql.parser.tree.Query)1 QueryMetadataHolder (io.confluent.ksql.rest.server.query.QueryMetadataHolder)1 KsqlException (io.confluent.ksql.util.KsqlException)1 KsqlStatementException (io.confluent.ksql.util.KsqlStatementException)1 TopicAuthorizationException (org.apache.kafka.common.errors.TopicAuthorizationException)1