use of io.confluent.ksql.rest.server.resources.IncompatibleKsqlCommandVersionException in project ksql by confluentinc.
the class CommandRunnerTest method shouldProcessPartialListOfCommandsOnIncompatibleCommandInRestore.
@Test
public void shouldProcessPartialListOfCommandsOnIncompatibleCommandInRestore() {
// Given:
givenQueuedCommands(queuedCommand1, queuedCommand2, queuedCommand3);
doThrow(new IncompatibleKsqlCommandVersionException("")).when(incompatibleCommandChecker).accept(queuedCommand3);
// When:
commandRunner.processPriorCommands(persistentQueryCleanupImpl);
commandRunner.start();
final Runnable threadTask = getThreadTask();
threadTask.run();
// Then:
final InOrder inOrder = inOrder(statementExecutor);
inOrder.verify(statementExecutor).handleRestore(eq(queuedCommand1));
inOrder.verify(statementExecutor).handleRestore(eq(queuedCommand2));
assertThat(commandRunner.checkCommandRunnerStatus(), is(CommandRunner.CommandRunnerStatus.DEGRADED));
assertThat(commandRunner.getCommandRunnerDegradedWarning(), is(INCOMPATIBLE_COMMANDS_ERROR_MESSAGE));
assertThat(commandRunner.getCommandRunnerDegradedReason(), is(CommandRunner.CommandRunnerDegradedReason.INCOMPATIBLE_COMMAND));
verify(statementExecutor, never()).handleRestore(queuedCommand3);
}
use of io.confluent.ksql.rest.server.resources.IncompatibleKsqlCommandVersionException in project ksql by confluentinc.
the class CommandTest method shouldThrowExceptionWhenCommandVersionHigher.
@Test
public void shouldThrowExceptionWhenCommandVersionHigher() {
final String commandStr = "{" + "\"statement\": \"test statement;\", " + "\"streamsProperties\": {\"foo\": \"bar\"}, " + "\"originalProperties\": {\"biz\": \"baz\"}, " + "\"version\": " + (Command.VERSION + 1) + "}";
final ObjectMapper mapper = PlanJsonMapper.INSTANCE.get();
final ValueInstantiationException thrown = assertThrows("Expected deserialization to throw, but it didn't", ValueInstantiationException.class, () -> mapper.readValue(commandStr, Command.class));
assertTrue(thrown.getCause() instanceof IncompatibleKsqlCommandVersionException);
}
use of io.confluent.ksql.rest.server.resources.IncompatibleKsqlCommandVersionException in project ksql by confluentinc.
the class CommandRunnerTest method shouldProcessPartialListOfCommandsOnIncompatibleCommandInFetch.
@Test
public void shouldProcessPartialListOfCommandsOnIncompatibleCommandInFetch() {
// Given:
givenQueuedCommands(queuedCommand1, queuedCommand2, queuedCommand3);
doThrow(new IncompatibleKsqlCommandVersionException("")).when(incompatibleCommandChecker).accept(queuedCommand3);
// When:
commandRunner.start();
final Runnable threadTask = getThreadTask();
threadTask.run();
// Then:
final InOrder inOrder = inOrder(statementExecutor);
inOrder.verify(statementExecutor).handleStatement(eq(queuedCommand1));
inOrder.verify(statementExecutor).handleStatement(eq(queuedCommand2));
assertThat(commandRunner.checkCommandRunnerStatus(), is(CommandRunner.CommandRunnerStatus.DEGRADED));
assertThat(commandRunner.getCommandRunnerDegradedWarning(), is(INCOMPATIBLE_COMMANDS_ERROR_MESSAGE));
assertThat(commandRunner.getCommandRunnerDegradedReason(), is(CommandRunner.CommandRunnerDegradedReason.INCOMPATIBLE_COMMAND));
verify(statementExecutor, never()).handleStatement(queuedCommand3);
}
use of io.confluent.ksql.rest.server.resources.IncompatibleKsqlCommandVersionException in project ksql by confluentinc.
the class KsqlRestoreCommandTopic method checkValidCommands.
/**
* Checks all CommandId and Command pairs to see if they're compatible with the current
* server version. If skipIncompatibleCommands is true, skip the command and try to clean up
* streams state stores and internal topics if the command being skipped is a query.
* If false, throw an exception when an incomptaible command is detected.
*
* @param records a list of CommandId and Command pairs
* @param skipIncompatibleCommands whether or not to throw an exception on incompatible commands
* @param ksqlConfig the {@link KsqlConfig} used by the program
* @return a list of compatible CommandId and Command pairs
*/
private static List<Pair<byte[], byte[]>> checkValidCommands(final List<Pair<byte[], byte[]>> records, final boolean skipIncompatibleCommands, final KsqlConfig ksqlConfig) {
int n = 0;
int numFilteredCommands = 0;
final List<Pair<byte[], byte[]>> filteredRecords = new ArrayList<>();
final List<byte[]> incompatibleCommands = new ArrayList<>();
for (final Pair<byte[], byte[]> record : records) {
n++;
try {
InternalTopicSerdes.deserializer(CommandId.class).deserialize(null, record.getLeft());
} catch (final Exception e) {
throw new KsqlException(String.format("Invalid CommandId string (line %d): %s (%s)", n, new String(record.getLeft(), StandardCharsets.UTF_8), e.getMessage()));
}
try {
InternalTopicSerdes.deserializer(Command.class).deserialize(null, record.getRight());
} catch (final SerializationException | IncompatibleKsqlCommandVersionException e) {
if (skipIncompatibleCommands) {
incompatibleCommands.add(record.getRight());
numFilteredCommands++;
continue;
} else {
throw new KsqlException(String.format("Incompatible Command string (line %d): %s (%s)", n, new String(record.getLeft(), StandardCharsets.UTF_8), e.getMessage()));
}
} catch (final Exception e) {
throw new KsqlException(String.format("Invalid Command string (line %d): %s (%s)", n, new String(record.getRight(), StandardCharsets.UTF_8), e.getMessage()));
}
filteredRecords.add(record);
}
if (skipIncompatibleCommands) {
System.out.println(String.format("%s incompatible command(s) skipped from backup file.", numFilteredCommands));
incompatibleCommands.forEach(command -> maybeCleanUpQuery(command, ksqlConfig));
}
return filteredRecords;
}
Aggregations