Search in sources :

Example 1 with KsqlConfigResolver

use of io.confluent.ksql.config.KsqlConfigResolver in project ksql by confluentinc.

the class ValidatedCommandFactory method createForAlterSystemQuery.

private static Command createForAlterSystemQuery(final ConfiguredStatement<? extends Statement> statement, final KsqlExecutionContext context) {
    final AlterSystemProperty alterSystemProperty = (AlterSystemProperty) statement.getStatement();
    final String propertyName = alterSystemProperty.getPropertyName();
    final String propertyValue = alterSystemProperty.getPropertyValue();
    // raise exception if feature flag is set
    if (!context.getKsqlConfig().getBoolean(KsqlConfig.KSQL_SHARED_RUNTIME_ENABLED)) {
        throw new KsqlServerException("Cannot alter system configs " + "when KSQL_SHARED_RUNTIME_ENABLED is turned off.");
    }
    // validate
    context.alterSystemProperty(propertyName, propertyValue);
    if (!Property.isEditable(propertyName)) {
        throw new ConfigException(String.format("Failed to set %s to %s. Caused by: " + "Not recognizable as ksql, streams, consumer, or producer property: %s %n", propertyName, propertyValue, propertyName), null);
    }
    // verify that no persistent query is running when attempting to change 'processing.guarantee'
    final KsqlConfigResolver resolver = new KsqlConfigResolver();
    final Optional<ConfigItem> resolvedItem = resolver.resolve(propertyName, false);
    if (resolvedItem.isPresent() && Objects.equals(resolvedItem.get().getPropertyName(), PROCESSING_GUARANTEE_CONFIG) && !context.getPersistentQueries().isEmpty()) {
        final Collection<QueryId> runningQueries = context.getPersistentQueries().stream().map(QueryMetadata::getQueryId).collect(Collectors.toList());
        LOG.error("Failed to set {} to {} due to the {} persistent queries currently running: {}", propertyName, propertyValue, runningQueries.size(), runningQueries);
        throw new ConfigException(String.format("Unable to set %s to %s, as the %s may not be changed for running" + " persistent queries which have already processed data under a" + " different %s. To modify %s you must first terminate all running" + " persistent queries.", propertyName, propertyValue, propertyName, propertyName, propertyName));
    }
    return Command.of(statement);
}
Also used : KsqlConfigResolver(io.confluent.ksql.config.KsqlConfigResolver) QueryId(io.confluent.ksql.query.QueryId) AlterSystemProperty(io.confluent.ksql.parser.tree.AlterSystemProperty) ConfigItem(io.confluent.ksql.config.ConfigItem) ConfigException(org.apache.kafka.common.config.ConfigException) KsqlServerException(io.confluent.ksql.util.KsqlServerException)

Example 2 with KsqlConfigResolver

use of io.confluent.ksql.config.KsqlConfigResolver in project ksql by confluentinc.

the class ListPropertiesExecutor method execute.

public static StatementExecutorResponse execute(final ConfiguredStatement<ListProperties> statement, final SessionProperties sessionProperties, final KsqlExecutionContext executionContext, final ServiceContext serviceContext) {
    final KsqlConfigResolver resolver = new KsqlConfigResolver();
    final Map<String, String> engineProperties = statement.getSessionConfig().getConfig(false).getAllConfigPropsWithSecretsObfuscated();
    final List<Property> mergedProperties = mergedProperties(statement);
    final List<String> overwritten = mergedProperties.stream().filter(property -> !Objects.equals(engineProperties.get(property.getName()), property.getValue())).map(Property::getName).collect(Collectors.toList());
    final List<String> defaultProps = mergedProperties.stream().filter(property -> resolver.resolve(property.getName(), false).map(resolved -> resolved.isDefaultValue(property.getValue())).orElse(false)).map(Property::getName).collect(Collectors.toList());
    return StatementExecutorResponse.handled(Optional.of(new PropertiesList(statement.getStatementText(), mergedProperties, overwritten, defaultProps)));
}
Also used : KsqlConfigResolver(io.confluent.ksql.config.KsqlConfigResolver) PropertiesList(io.confluent.ksql.rest.entity.PropertiesList) Property(io.confluent.ksql.rest.entity.PropertiesList.Property)

Aggregations

KsqlConfigResolver (io.confluent.ksql.config.KsqlConfigResolver)2 ConfigItem (io.confluent.ksql.config.ConfigItem)1 AlterSystemProperty (io.confluent.ksql.parser.tree.AlterSystemProperty)1 QueryId (io.confluent.ksql.query.QueryId)1 PropertiesList (io.confluent.ksql.rest.entity.PropertiesList)1 Property (io.confluent.ksql.rest.entity.PropertiesList.Property)1 KsqlServerException (io.confluent.ksql.util.KsqlServerException)1 ConfigException (org.apache.kafka.common.config.ConfigException)1