use of io.confluent.ksql.rest.entity.CommandStatus in project ksql by confluentinc.
the class StatementExecutor method handleStatementWithTerminatedQueries.
/**
* Attempt to execute a single statement.
*
* @param command The string containing the statement to be executed
* @param commandId The ID to be used to track the status of the command
* @param terminatedQueries An optional map from terminated query IDs to the commands that
* requested their termination
* @param wasDropped was this table/stream subsequently dropped
* @throws Exception TODO: Refine this.
*/
private void handleStatementWithTerminatedQueries(Command command, CommandId commandId, Map<QueryId, CommandId> terminatedQueries, boolean wasDropped) throws Exception {
try {
String statementString = command.getStatement();
statusStore.put(commandId, new CommandStatus(CommandStatus.Status.PARSING, "Parsing statement"));
Statement statement = statementParser.parseSingleStatement(statementString);
statusStore.put(commandId, new CommandStatus(CommandStatus.Status.EXECUTING, "Executing statement"));
executeStatement(statement, command, commandId, terminatedQueries, wasDropped);
} catch (WakeupException exception) {
throw exception;
} catch (Exception exception) {
log.error("Failed to handle: " + command, exception);
CommandStatus errorStatus = new CommandStatus(CommandStatus.Status.ERROR, ExceptionUtil.stackTraceToString(exception));
statusStore.put(commandId, errorStatus);
completeStatusFuture(commandId, errorStatus);
}
}
use of io.confluent.ksql.rest.entity.CommandStatus in project ksql by confluentinc.
the class StatementExecutor method terminateQuery.
private void terminateQuery(TerminateQuery terminateQuery) throws Exception {
final QueryId queryId = terminateQuery.getQueryId();
final QueryMetadata queryMetadata = ksqlEngine.getPersistentQueries().get(queryId);
if (!ksqlEngine.terminateQuery(queryId, true)) {
throw new Exception(String.format("No running query with id %s was found", queryId));
}
CommandId.Type commandType;
DataSource.DataSourceType sourceType = queryMetadata.getOutputNode().getTheSourceNode().getDataSourceType();
switch(sourceType) {
case KTABLE:
commandType = CommandId.Type.TABLE;
break;
case KSTREAM:
commandType = CommandId.Type.STREAM;
break;
default:
throw new Exception(String.format("Unexpected source type for running query: %s", sourceType));
}
String queryEntity = ((KsqlStructuredDataOutputNode) queryMetadata.getOutputNode()).getKsqlTopic().getName();
CommandId queryStatementId = new CommandId(commandType, queryEntity, CommandId.Action.CREATE);
statusStore.put(queryStatementId, new CommandStatus(CommandStatus.Status.TERMINATED, "Query terminated"));
}
use of io.confluent.ksql.rest.entity.CommandStatus in project ksql by confluentinc.
the class StatementExecutor method registerQueuedStatement.
/**
* Register the existence of a new statement that has been written to the command topic. All other
* statement status information is updated exclusively by the current {@link StatementExecutor}
* instance, but in the (unlikely but possible) event that a statement is written to the command
* topic but never picked up by this instance, it should be possible to know that it was at least
* written to the topic in the first place.
*
* @param commandId The ID of the statement that has been written to the command topic.
*/
public Future<CommandStatus> registerQueuedStatement(CommandId commandId) {
statusStore.put(commandId, new CommandStatus(CommandStatus.Status.QUEUED, "Statement written to command topic"));
CommandStatusFuture result;
synchronized (statusFutures) {
result = statusFutures.get(commandId);
if (result != null) {
return result;
} else {
result = new CommandStatusFuture(commandId, statusFutures::remove);
statusFutures.put(commandId, result);
return result;
}
}
}
Aggregations