Search in sources :

Example 11 with SessionProperties

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)));
}
Also used : SessionProperties(io.confluent.ksql.rest.SessionProperties) KsqlHostInfo(io.confluent.ksql.util.KsqlHostInfo) UnsetProperty(io.confluent.ksql.parser.tree.UnsetProperty) Matchers.containsString(org.hamcrest.Matchers.containsString) URL(java.net.URL) Test(org.junit.Test)

Example 12 with SessionProperties

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"));
}
Also used : SessionProperties(io.confluent.ksql.rest.SessionProperties) KsqlHostInfo(io.confluent.ksql.util.KsqlHostInfo) SetProperty(io.confluent.ksql.parser.tree.SetProperty) URL(java.net.URL) KsqlStatementException(io.confluent.ksql.util.KsqlStatementException) Test(org.junit.Test)

Example 13 with SessionProperties

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())));
}
Also used : DataSource(io.confluent.ksql.metastore.model.DataSource) StreamsList(io.confluent.ksql.rest.entity.StreamsList) SessionProperties(io.confluent.ksql.rest.SessionProperties) SourceName(io.confluent.ksql.name.SourceName) QueryOffsetSummary(io.confluent.ksql.rest.entity.QueryOffsetSummary) RunningQuery(io.confluent.ksql.rest.entity.RunningQuery) DescribeTables(io.confluent.ksql.parser.tree.DescribeTables) ServiceContext(io.confluent.ksql.services.ServiceContext) KafkaException(org.apache.kafka.common.KafkaException) QueryTopicOffsetSummary(io.confluent.ksql.rest.entity.QueryTopicOffsetSummary) SourceDescription(io.confluent.ksql.rest.entity.SourceDescription) Map(java.util.Map) QueryId(io.confluent.ksql.query.QueryId) SourceDescriptionList(io.confluent.ksql.rest.entity.SourceDescriptionList) PersistentQueryMetadata(io.confluent.ksql.util.PersistentQueryMetadata) KsqlTable(io.confluent.ksql.metastore.model.KsqlTable) TopicPartition(org.apache.kafka.common.TopicPartition) ImmutableSet(com.google.common.collect.ImmutableSet) Predicate(java.util.function.Predicate) Collection(java.util.Collection) Set(java.util.Set) ConfiguredStatement(io.confluent.ksql.statement.ConfiguredStatement) KsqlConfig(io.confluent.ksql.util.KsqlConfig) KafkaResponseGetFailedException(io.confluent.ksql.exception.KafkaResponseGetFailedException) Collectors(java.util.stream.Collectors) List(java.util.List) KsqlExecutionContext(io.confluent.ksql.KsqlExecutionContext) Entry(java.util.Map.Entry) OffsetAndMetadata(org.apache.kafka.clients.consumer.OffsetAndMetadata) Optional(java.util.Optional) KsqlConstants(io.confluent.ksql.util.KsqlConstants) KsqlRestApplication(io.confluent.ksql.rest.server.KsqlRestApplication) HashMap(java.util.HashMap) Multimap(com.google.common.collect.Multimap) ArrayList(java.util.ArrayList) KsqlEntity(io.confluent.ksql.rest.entity.KsqlEntity) HashSet(java.util.HashSet) QueryStatusCount(io.confluent.ksql.rest.entity.QueryStatusCount) ImmutableList(com.google.common.collect.ImmutableList) SourceDescriptionEntity(io.confluent.ksql.rest.entity.SourceDescriptionEntity) MetaStore(io.confluent.ksql.metastore.MetaStore) ShowColumns(io.confluent.ksql.parser.tree.ShowColumns) DescribeStreams(io.confluent.ksql.parser.tree.DescribeStreams) TablesList(io.confluent.ksql.rest.entity.TablesList) TopicDescription(org.apache.kafka.clients.admin.TopicDescription) ImmutableMultimap(com.google.common.collect.ImmutableMultimap) LinkedList(java.util.LinkedList) ListTables(io.confluent.ksql.parser.tree.ListTables) TopicPartitionInfo(org.apache.kafka.common.TopicPartitionInfo) Table(io.confluent.ksql.rest.entity.SourceInfo.Table) ListStreams(io.confluent.ksql.parser.tree.ListStreams) QueryApplicationId(io.confluent.ksql.util.QueryApplicationId) SourceDescriptionFactory(io.confluent.ksql.rest.entity.SourceDescriptionFactory) KsqlStream(io.confluent.ksql.metastore.model.KsqlStream) KsqlStatementException(io.confluent.ksql.util.KsqlStatementException) StatementWithExtendedClause(io.confluent.ksql.parser.tree.StatementWithExtendedClause) ConsumerPartitionOffsets(io.confluent.ksql.rest.entity.ConsumerPartitionOffsets) Stream(io.confluent.ksql.rest.entity.SourceInfo.Stream) Collections(java.util.Collections) KsqlWarning(io.confluent.ksql.rest.entity.KsqlWarning) SourceDescriptionList(io.confluent.ksql.rest.entity.SourceDescriptionList) SourceDescription(io.confluent.ksql.rest.entity.SourceDescription)

Example 14 with SessionProperties

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();
    }
}
Also used : KsqlEntityList(io.confluent.ksql.rest.entity.KsqlEntityList) SessionProperties(io.confluent.ksql.rest.SessionProperties) KsqlEngine(io.confluent.ksql.engine.KsqlEngine) KsqlEntityList(io.confluent.ksql.rest.entity.KsqlEntityList) ConfiguredStatement(io.confluent.ksql.statement.ConfiguredStatement) KsqlConfig(io.confluent.ksql.util.KsqlConfig) FeatureFlagChecker(io.confluent.ksql.rest.util.FeatureFlagChecker) KsqlSecurityContext(io.confluent.ksql.security.KsqlSecurityContext) DistributingExecutor(io.confluent.ksql.rest.server.computation.DistributingExecutor) SessionConfig(io.confluent.ksql.config.SessionConfig) KsqlEntity(io.confluent.ksql.rest.entity.KsqlEntity) Objects(java.util.Objects) List(java.util.List) Map(java.util.Map) ParsedStatement(io.confluent.ksql.parser.KsqlParser.ParsedStatement) Optional(java.util.Optional) Statement(io.confluent.ksql.parser.tree.Statement) Collections(java.util.Collections) PreparedStatement(io.confluent.ksql.parser.KsqlParser.PreparedStatement)

Example 15 with SessionProperties

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());
    }
}
Also used : KsqlEntityList(io.confluent.ksql.rest.entity.KsqlEntityList) SessionProperties(io.confluent.ksql.rest.SessionProperties) PatternSyntaxException(java.util.regex.PatternSyntaxException) KsqlException(io.confluent.ksql.util.KsqlException) KsqlStatementException(io.confluent.ksql.util.KsqlStatementException)

Aggregations

SessionProperties (io.confluent.ksql.rest.SessionProperties)15 KsqlHostInfo (io.confluent.ksql.util.KsqlHostInfo)7 ConfiguredStatement (io.confluent.ksql.statement.ConfiguredStatement)6 KsqlStatementException (io.confluent.ksql.util.KsqlStatementException)6 URL (java.net.URL)6 List (java.util.List)6 Optional (java.util.Optional)6 Test (org.junit.Test)6 KsqlExecutionContext (io.confluent.ksql.KsqlExecutionContext)5 ServiceContext (io.confluent.ksql.services.ServiceContext)4 Map (java.util.Map)4 SetProperty (io.confluent.ksql.parser.tree.SetProperty)3 UnsetProperty (io.confluent.ksql.parser.tree.UnsetProperty)3 KsqlWarning (io.confluent.ksql.rest.entity.KsqlWarning)3 Collectors (java.util.stream.Collectors)3 ImmutableList (com.google.common.collect.ImmutableList)2 ParsedStatement (io.confluent.ksql.parser.KsqlParser.ParsedStatement)2 QueryId (io.confluent.ksql.query.QueryId)2 KsqlEntity (io.confluent.ksql.rest.entity.KsqlEntity)2 KsqlEntityList (io.confluent.ksql.rest.entity.KsqlEntityList)2