use of io.confluent.ksql.rest.SessionProperties in project ksql by confluentinc.
the class PropertyExecutorTest method shouldUnSetProperty.
@Test
public void shouldUnSetProperty() {
// Given:
engine.givenSource(DataSourceType.KSTREAM, "stream");
final SessionProperties sessionProperties = new SessionProperties(Collections.singletonMap(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "none"), mock(KsqlHostInfo.class), mock(URL.class), false);
final Map<String, Object> properties = sessionProperties.getMutableScopedProperties();
// When:
CUSTOM_EXECUTORS.unsetProperty().execute((ConfiguredStatement<UnsetProperty>) engine.configure("UNSET '" + ConsumerConfig.AUTO_OFFSET_RESET_CONFIG + "';"), sessionProperties, engine.getEngine(), engine.getServiceContext());
// Then:
assertThat(properties, not(hasKey(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG)));
}
use of io.confluent.ksql.rest.SessionProperties in project ksql by confluentinc.
the class PropertyOverriderTest method shouldFailOnUnknownUnsetProperty.
@Test
public void shouldFailOnUnknownUnsetProperty() {
// Given:
final Map<String, Object> properties = new HashMap<>();
final SessionProperties sessionProperties = new SessionProperties(properties, mock(KsqlHostInfo.class), mock(URL.class), false);
// When:
final Exception e = assertThrows(KsqlStatementException.class, () -> CustomValidators.UNSET_PROPERTY.validate(ConfiguredStatement.of(PreparedStatement.of("UNSET 'consumer.invalid';", new UnsetProperty(Optional.empty(), "consumer.invalid")), SessionConfig.of(engine.getKsqlConfig(), new HashMap<>())), sessionProperties, engine.getEngine(), engine.getServiceContext()));
// Then:
assertThat(e.getMessage(), containsString("Unknown property: consumer.invalid"));
}
use of io.confluent.ksql.rest.SessionProperties in project ksql by confluentinc.
the class PropertyOverriderTest method shouldAllowSetKnownProperty.
@Test
public void shouldAllowSetKnownProperty() {
// Given:
final SessionProperties sessionProperties = new SessionProperties(new HashedMap<>(), mock(KsqlHostInfo.class), mock(URL.class), false);
final Map<String, Object> properties = sessionProperties.getMutableScopedProperties();
// When:
CustomValidators.SET_PROPERTY.validate(ConfiguredStatement.of(PreparedStatement.of("SET '" + ConsumerConfig.AUTO_OFFSET_RESET_CONFIG + "' = 'earliest';", new SetProperty(Optional.empty(), ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest")), SessionConfig.of(engine.getKsqlConfig(), ImmutableMap.of())), sessionProperties, engine.getEngine(), engine.getServiceContext());
// Then:
assertThat(properties, hasEntry(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest"));
}
use of io.confluent.ksql.rest.SessionProperties in project ksql by confluentinc.
the class TestExecutorUtil method execute.
/**
* @param srClient if supplied, then schemas can be inferred from the schema registry.
* @return a list of persistent queries that should be run by the test executor, if a query was
* replaced via a CREATE OR REPLACE statement it will only appear once in the output list
*/
@SuppressWarnings("OptionalGetWithoutIsPresent")
private static List<PersistentQueryAndSources> execute(final KsqlEngine engine, final TestCase testCase, final KsqlConfig ksqlConfig, final ServiceContext serviceContext, final Optional<SchemaRegistryClient> srClient, final StubKafkaService stubKafkaService, final TestExecutionListener listener) {
final Map<QueryId, PersistentQueryAndSources> queries = new LinkedHashMap<>();
int idx = 0;
final Iterator<PlannedStatement> plans = planTestCase(engine, testCase, ksqlConfig, serviceContext, srClient, stubKafkaService);
try {
while (plans.hasNext()) {
++idx;
final PlannedStatement planned = plans.next();
if (planned.insertValues.isPresent()) {
final ConfiguredStatement<InsertValues> insertValues = planned.insertValues.get();
final SessionProperties sessionProperties = new SessionProperties(insertValues.getSessionConfig().getOverrides(), new KsqlHostInfo("host", 50), buildUrl(), false);
StubInsertValuesExecutor.of(stubKafkaService).execute(insertValues, sessionProperties, engine, engine.getServiceContext());
continue;
}
final ConfiguredKsqlPlan plan = planned.plan.orElseThrow(IllegalStateException::new);
listener.acceptPlan(plan);
final ExecuteResultAndSources result = executePlan(engine, plan);
if (!result.getSources().isPresent()) {
continue;
}
final PersistentQueryMetadata query = (PersistentQueryMetadata) result.getExecuteResult().getQuery().get();
listener.acceptQuery(query);
queries.put(query.getQueryId(), new PersistentQueryAndSources(query, result.getSources().get()));
}
return ImmutableList.copyOf(queries.values());
} catch (final KsqlStatementException e) {
if (testCase.expectedException().isPresent() && plans.hasNext()) {
throw new AssertionError("Only the last statement in a negative test should fail. " + "Yet in this case statement " + idx + " failed.", e);
}
throw e;
}
}
use of io.confluent.ksql.rest.SessionProperties 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()));
}
}
Aggregations