use of io.confluent.ksql.util.KsqlServerException in project ksql by confluentinc.
the class LocalCommands method processLocalCommandFiles.
public void processLocalCommandFiles(final ServiceContext serviceContext) {
final FilenameFilter filter = (dir, fileName) -> fileName.endsWith(LOCAL_COMMANDS_FILE_SUFFIX);
final File[] files = directory.listFiles(filter);
if (files == null) {
throw new KsqlServerException("Bad local commands directory " + directory.getAbsolutePath() + ". Please check your configuration for " + KsqlRestConfig.KSQL_LOCAL_COMMANDS_LOCATION_CONFIG);
}
for (final File file : files) {
if (file.equals(currentLocalCommands.getFile())) {
continue;
}
try (LocalCommandsFile localCommandsFile = LocalCommandsFile.createReadonly(file)) {
final List<LocalCommand> localCommands = localCommandsFile.readRecords();
cleanUpTransientQueryState(localCommands, serviceContext);
markFileAsProcessed(file);
} catch (Exception e) {
LOG.error("Error processing local commands " + file.getAbsolutePath() + ". There may be orphaned transient topics or abandoned state stores.", e);
}
}
}
use of io.confluent.ksql.util.KsqlServerException in project ksql by confluentinc.
the class DistributingExecutor method checkAuthorization.
private void checkAuthorization(final ConfiguredStatement<?> configured, final KsqlSecurityContext userSecurityContext, final KsqlExecutionContext serverExecutionContext) {
final Statement statement = configured.getStatement();
final MetaStore metaStore = serverExecutionContext.getMetaStore();
// Check the User will be permitted to execute this statement
authorizationValidator.ifPresent(validator -> validator.checkAuthorization(userSecurityContext, metaStore, statement));
try {
// Check the KSQL service principal will be permitted too
authorizationValidator.ifPresent(validator -> validator.checkAuthorization(new KsqlSecurityContext(Optional.empty(), serverExecutionContext.getServiceContext()), metaStore, statement));
} catch (final Exception e) {
throw new KsqlServerException("The KSQL server is not permitted to execute the command", e);
}
}
use of io.confluent.ksql.util.KsqlServerException 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);
}
use of io.confluent.ksql.util.KsqlServerException in project ksql by confluentinc.
the class CommandStore method waitForCommandConsumer.
@Override
public void waitForCommandConsumer() {
try {
final long endOffset = getCommandTopicOffset();
ensureConsumedPast(endOffset - 1, commandQueueCatchupTimeout);
} catch (final InterruptedException e) {
final String errorMsg = "Interrupted while waiting for command topic consumer to process command topic";
throw new KsqlServerException(errorMsg);
} catch (final TimeoutException e) {
final String errorMsg = "Timeout while waiting for command topic consumer to process command topic";
throw new KsqlServerException(errorMsg);
}
}
use of io.confluent.ksql.util.KsqlServerException in project ksql by confluentinc.
the class KsqlEngine method getEndOffsetsForStreamPullQuery.
private ImmutableMap<TopicPartition, Long> getEndOffsetsForStreamPullQuery(final Admin admin, final TopicDescription topicDescription) {
final Map<TopicPartition, OffsetSpec> topicPartitions = topicDescription.partitions().stream().map(td -> new TopicPartition(topicDescription.name(), td.partition())).collect(toMap(identity(), tp -> OffsetSpec.latest()));
final ListOffsetsResult listOffsetsResult = admin.listOffsets(topicPartitions, // so we should do the same when checking end offsets.
new ListOffsetsOptions(IsolationLevel.READ_UNCOMMITTED));
final ImmutableMap<TopicPartition, Long> startOffsetsForStreamPullQuery = getStartOffsetsForStreamPullQuery(admin, topicDescription);
try {
final Map<TopicPartition, ListOffsetsResult.ListOffsetsResultInfo> partitionResultMap = listOffsetsResult.all().get(10, TimeUnit.SECONDS);
final Map<TopicPartition, Long> result = partitionResultMap.entrySet().stream().filter(e -> e.getValue().offset() > 0L && e.getValue().offset() > startOffsetsForStreamPullQuery.get(e.getKey())).collect(toMap(Entry::getKey, e -> e.getValue().offset()));
return ImmutableMap.copyOf(result);
} catch (final InterruptedException e) {
log.error("Admin#listOffsets(" + topicDescription.name() + ") interrupted", e);
throw new KsqlServerException("Interrupted");
} catch (final ExecutionException e) {
log.error("Error executing Admin#listOffsets(" + topicDescription.name() + ")", e);
throw new KsqlServerException("Internal Server Error");
} catch (final TimeoutException e) {
log.error("Admin#listOffsets(" + topicDescription.name() + ") timed out", e);
throw new KsqlServerException("Backend timed out");
}
}
Aggregations