Search in sources :

Example 1 with AlterSystemProperty

use of io.confluent.ksql.parser.tree.AlterSystemProperty 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 AlterSystemProperty

use of io.confluent.ksql.parser.tree.AlterSystemProperty in project ksql by confluentinc.

the class KsqlParserTest method testAlterSystemProperties.

@Test
public void testAlterSystemProperties() {
    final String simpleQuery = "ALTER SYSTEM 'ksql.persistent.prefix'='test';";
    final Statement statement = KsqlParserTestUtil.buildSingleAst(simpleQuery, metaStore).getStatement();
    Assert.assertTrue(statement instanceof AlterSystemProperty);
    final AlterSystemProperty alterSystemProperty = (AlterSystemProperty) statement;
    assertThat(alterSystemProperty.toString(), is("AlterSystemProperty{propertyName='ksql.persistent.prefix', propertyValue='test'}"));
    assertThat(alterSystemProperty.getPropertyName(), is("ksql.persistent.prefix"));
    assertThat(alterSystemProperty.getPropertyValue(), is("test"));
}
Also used : Statement(io.confluent.ksql.parser.tree.Statement) PreparedStatement(io.confluent.ksql.parser.KsqlParser.PreparedStatement) AlterSystemProperty(io.confluent.ksql.parser.tree.AlterSystemProperty) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 3 with AlterSystemProperty

use of io.confluent.ksql.parser.tree.AlterSystemProperty in project ksql by confluentinc.

the class InteractiveStatementExecutor method executeStatement.

@SuppressWarnings("unchecked")
private void executeStatement(final PreparedStatement<?> statement, final CommandId commandId, final Optional<CommandStatusFuture> commandStatusFuture) {
    if (statement.getStatement() instanceof TerminateQuery) {
        terminateQuery((PreparedStatement<TerminateQuery>) statement);
        final String successMessage = "Query terminated.";
        final CommandStatus successStatus = new CommandStatus(CommandStatus.Status.SUCCESS, successMessage, Optional.empty());
        putFinalStatus(commandId, commandStatusFuture, successStatus);
    } else if (statement.getStatement() instanceof ExecutableDdlStatement) {
        throwUnsupportedStatementError();
    } else if (statement.getStatement() instanceof CreateAsSelect) {
        throwUnsupportedStatementError();
    } else if (statement.getStatement() instanceof InsertInto) {
        throwUnsupportedStatementError();
    } else if (statement.getStatement() instanceof AlterSystemProperty) {
        final PreparedStatement<AlterSystemProperty> alterSystemQuery = (PreparedStatement<AlterSystemProperty>) statement;
        final String propertyName = alterSystemQuery.getStatement().getPropertyName();
        final String propertyValue = alterSystemQuery.getStatement().getPropertyValue();
        ksqlEngine.alterSystemProperty(propertyName, propertyValue);
        ksqlEngine.updateStreamsPropertiesAndRestartRuntime();
        final String successMessage = String.format("System property %s was set to %s.", propertyName, propertyValue);
        final CommandStatus successStatus = new CommandStatus(CommandStatus.Status.SUCCESS, successMessage, Optional.empty());
        putFinalStatus(commandId, commandStatusFuture, successStatus);
    } else {
        throw new KsqlException(String.format("Unexpected statement type: %s", statement.getClass().getName()));
    }
}
Also used : TerminateQuery(io.confluent.ksql.parser.tree.TerminateQuery) AlterSystemProperty(io.confluent.ksql.parser.tree.AlterSystemProperty) CommandStatus(io.confluent.ksql.rest.entity.CommandStatus) InsertInto(io.confluent.ksql.parser.tree.InsertInto) PreparedStatement(io.confluent.ksql.parser.KsqlParser.PreparedStatement) ExecutableDdlStatement(io.confluent.ksql.parser.tree.ExecutableDdlStatement) CreateAsSelect(io.confluent.ksql.parser.tree.CreateAsSelect) KsqlException(io.confluent.ksql.util.KsqlException)

Aggregations

AlterSystemProperty (io.confluent.ksql.parser.tree.AlterSystemProperty)3 PreparedStatement (io.confluent.ksql.parser.KsqlParser.PreparedStatement)2 ConfigItem (io.confluent.ksql.config.ConfigItem)1 KsqlConfigResolver (io.confluent.ksql.config.KsqlConfigResolver)1 CreateAsSelect (io.confluent.ksql.parser.tree.CreateAsSelect)1 ExecutableDdlStatement (io.confluent.ksql.parser.tree.ExecutableDdlStatement)1 InsertInto (io.confluent.ksql.parser.tree.InsertInto)1 Statement (io.confluent.ksql.parser.tree.Statement)1 TerminateQuery (io.confluent.ksql.parser.tree.TerminateQuery)1 QueryId (io.confluent.ksql.query.QueryId)1 CommandStatus (io.confluent.ksql.rest.entity.CommandStatus)1 KsqlException (io.confluent.ksql.util.KsqlException)1 KsqlServerException (io.confluent.ksql.util.KsqlServerException)1 ConfigException (org.apache.kafka.common.config.ConfigException)1 Matchers.containsString (org.hamcrest.Matchers.containsString)1 Test (org.junit.Test)1