use of io.confluent.ksql.rest.SessionProperties in project ksql by confluentinc.
the class PropertyOverriderTest method shouldAllowUnsetKnownProperty.
@Test
public void shouldAllowUnsetKnownProperty() {
// Given:
final SessionProperties sessionProperties = new SessionProperties(Collections.singletonMap(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest"), mock(KsqlHostInfo.class), mock(URL.class), false);
final Map<String, Object> properties = sessionProperties.getMutableScopedProperties();
// When:
CustomValidators.UNSET_PROPERTY.validate(ConfiguredStatement.of(PreparedStatement.of("UNSET '" + ConsumerConfig.AUTO_OFFSET_RESET_CONFIG + "';", new UnsetProperty(Optional.empty(), ConsumerConfig.AUTO_OFFSET_RESET_CONFIG)), SessionConfig.of(engine.getKsqlConfig(), ImmutableMap.of())), 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 shouldFailOnInvalidSetPropertyValue.
@Test
public void shouldFailOnInvalidSetPropertyValue() {
// Given:
final SessionProperties sessionProperties = new SessionProperties(new HashedMap<>(), mock(KsqlHostInfo.class), mock(URL.class), false);
// When:
final Exception e = assertThrows(KsqlStatementException.class, () -> CustomValidators.SET_PROPERTY.validate(ConfiguredStatement.of(PreparedStatement.of("SET '" + ConsumerConfig.AUTO_OFFSET_RESET_CONFIG + "' = 'invalid';", new SetProperty(Optional.empty(), ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "invalid")), SessionConfig.of(engine.getKsqlConfig(), ImmutableMap.of())), sessionProperties, engine.getEngine(), engine.getServiceContext()));
// Then:
assertThat(e.getMessage(), containsString("Invalid value invalid"));
}
use of io.confluent.ksql.rest.SessionProperties in project ksql by confluentinc.
the class ListSourceExecutor method sourceDescriptionList.
private static Optional<KsqlEntity> sourceDescriptionList(final ConfiguredStatement<? extends StatementWithExtendedClause> statement, final SessionProperties sessionProperties, final KsqlExecutionContext executionContext, final ServiceContext serviceContext, final List<? extends DataSource> sources, final boolean extended) {
final RemoteHostExecutor remoteHostExecutor = RemoteHostExecutor.create(statement, sessionProperties, executionContext, serviceContext.getKsqlClient());
final Multimap<String, SourceDescription> remoteSourceDescriptions = extended ? RemoteSourceDescriptionExecutor.fetchSourceDescriptions(remoteHostExecutor) : ImmutableMultimap.of();
final List<SourceDescriptionWithWarnings> descriptions = sources.stream().map(s -> describeSource(statement.getSessionConfig().getConfig(false), executionContext, serviceContext, s.getName(), extended, statement, sessionProperties, remoteSourceDescriptions.get(s.getName().toString()))).collect(Collectors.toList());
return Optional.of(new SourceDescriptionList(statement.getStatementText(), descriptions.stream().map(d -> d.description).collect(Collectors.toList()), descriptions.stream().flatMap(d -> d.warnings.stream()).collect(Collectors.toList())));
}
use of io.confluent.ksql.rest.SessionProperties in project ksql by confluentinc.
the class RequestHandler method executeStatement.
@SuppressWarnings("unchecked")
private <T extends Statement> Optional<KsqlEntity> executeStatement(final KsqlSecurityContext securityContext, final PreparedStatement<T> prepared, final SessionProperties sessionProperties, final KsqlEntityList entities) {
final Class<? extends Statement> statementClass = prepared.getStatement().getClass();
commandQueueSync.waitFor(new KsqlEntityList(entities), statementClass);
final ConfiguredStatement<T> configured = ConfiguredStatement.of(prepared, SessionConfig.of(this.ksqlEngine.getKsqlConfig(), sessionProperties.getMutableScopedProperties()));
FeatureFlagChecker.throwOnDisabledFeatures(configured);
final StatementExecutor<T> executor = (StatementExecutor<T>) customExecutors.getOrDefault(statementClass, (stmt, props, ctx, svcCtx) -> distributor.execute(stmt, ctx, securityContext));
final StatementExecutorResponse response = executor.execute(configured, sessionProperties, ksqlEngine, securityContext.getServiceContext());
if (response.isHandled()) {
return response.getEntity();
} else {
return distributor.execute(configured, ksqlEngine, securityContext).getEntity();
}
}
use of io.confluent.ksql.rest.SessionProperties in project ksql by confluentinc.
the class KsqlResource method terminateCluster.
public EndpointResponse terminateCluster(final KsqlSecurityContext securityContext, final ClusterTerminateRequest request) {
LOG.info("Received: " + request);
throwIfNotConfigured();
ensureValidPatterns(request.getDeleteTopicList());
try {
final Map<String, Object> streamsProperties = request.getStreamsProperties();
denyListPropertyValidator.validateAll(streamsProperties);
final KsqlEntityList entities = handler.execute(securityContext, TERMINATE_CLUSTER, new SessionProperties(streamsProperties, localHost, localUrl, false));
return EndpointResponse.ok(entities);
} catch (final Exception e) {
return Errors.serverErrorForStatement(e, TerminateCluster.TERMINATE_CLUSTER_STATEMENT_TEXT, new KsqlEntityList());
}
}
Aggregations