Search in sources :

Example 1 with KsqlRequestConfig

use of io.confluent.ksql.util.KsqlRequestConfig in project ksql by confluentinc.

the class KsqlResource method handleKsqlStatements.

public EndpointResponse handleKsqlStatements(final KsqlSecurityContext securityContext, final KsqlRequest request) {
    LOG.info("Received: " + request);
    throwIfNotConfigured();
    activenessRegistrar.updateLastRequestTime();
    try {
        CommandStoreUtil.httpWaitForCommandSequenceNumber(commandRunner.getCommandQueue(), request, distributedCmdResponseTimeout);
        final Map<String, Object> configProperties = request.getConfigOverrides();
        denyListPropertyValidator.validateAll(configProperties);
        final KsqlRequestConfig requestConfig = new KsqlRequestConfig(request.getRequestProperties());
        final List<ParsedStatement> statements = ksqlEngine.parse(request.getKsql());
        validator.validate(SandboxedServiceContext.create(securityContext.getServiceContext()), statements, new SessionProperties(configProperties, localHost, localUrl, requestConfig.getBoolean(KsqlRequestConfig.KSQL_REQUEST_INTERNAL_REQUEST), request.getSessionVariables()), request.getKsql());
        // log validated statements for query anonymization
        statements.forEach(s -> {
            if (s.getStatementText().toLowerCase().contains("terminate") || s.getStatementText().toLowerCase().contains("drop")) {
                QueryLogger.info("Query terminated", s.getStatementText());
            } else {
                QueryLogger.info("Query created", s.getStatementText());
            }
        });
        final KsqlEntityList entities = handler.execute(securityContext, statements, new SessionProperties(configProperties, localHost, localUrl, requestConfig.getBoolean(KsqlRequestConfig.KSQL_REQUEST_INTERNAL_REQUEST), request.getSessionVariables()));
        LOG.info("Processed successfully: " + request);
        addCommandRunnerWarning(entities, commandRunnerWarning);
        return EndpointResponse.ok(entities);
    } catch (final KsqlRestException e) {
        LOG.info("Processed unsuccessfully: " + request + ", reason: ", e);
        throw e;
    } catch (final KsqlStatementException e) {
        LOG.info("Processed unsuccessfully: " + request + ", reason: ", e);
        return Errors.badStatement(e.getRawMessage(), e.getSqlStatement());
    } catch (final KsqlException e) {
        LOG.info("Processed unsuccessfully: " + request + ", reason: ", e);
        return errorHandler.generateResponse(e, Errors.badRequest(e));
    } catch (final Exception e) {
        LOG.info("Processed unsuccessfully: " + request + ", reason: ", e);
        return errorHandler.generateResponse(e, Errors.serverErrorForStatement(e, request.getKsql()));
    }
}
Also used : KsqlEntityList(io.confluent.ksql.rest.entity.KsqlEntityList) SessionProperties(io.confluent.ksql.rest.SessionProperties) ParsedStatement(io.confluent.ksql.parser.KsqlParser.ParsedStatement) KsqlStatementException(io.confluent.ksql.util.KsqlStatementException) KsqlRequestConfig(io.confluent.ksql.util.KsqlRequestConfig) KsqlException(io.confluent.ksql.util.KsqlException) PatternSyntaxException(java.util.regex.PatternSyntaxException) KsqlException(io.confluent.ksql.util.KsqlException) KsqlStatementException(io.confluent.ksql.util.KsqlStatementException)

Aggregations

ParsedStatement (io.confluent.ksql.parser.KsqlParser.ParsedStatement)1 SessionProperties (io.confluent.ksql.rest.SessionProperties)1 KsqlEntityList (io.confluent.ksql.rest.entity.KsqlEntityList)1 KsqlException (io.confluent.ksql.util.KsqlException)1 KsqlRequestConfig (io.confluent.ksql.util.KsqlRequestConfig)1 KsqlStatementException (io.confluent.ksql.util.KsqlStatementException)1 PatternSyntaxException (java.util.regex.PatternSyntaxException)1