Search in sources :

Example 1 with IncompatibleKsqlCommandVersionException

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);
}
Also used : InOrder(org.mockito.InOrder) IncompatibleKsqlCommandVersionException(io.confluent.ksql.rest.server.resources.IncompatibleKsqlCommandVersionException) Test(org.junit.Test)

Example 2 with IncompatibleKsqlCommandVersionException

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);
}
Also used : ValueInstantiationException(com.fasterxml.jackson.databind.exc.ValueInstantiationException) IncompatibleKsqlCommandVersionException(io.confluent.ksql.rest.server.resources.IncompatibleKsqlCommandVersionException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 3 with 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);
}
Also used : InOrder(org.mockito.InOrder) IncompatibleKsqlCommandVersionException(io.confluent.ksql.rest.server.resources.IncompatibleKsqlCommandVersionException) Test(org.junit.Test)

Example 4 with IncompatibleKsqlCommandVersionException

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;
}
Also used : SerializationException(org.apache.kafka.common.errors.SerializationException) ArrayList(java.util.ArrayList) KsqlException(io.confluent.ksql.util.KsqlException) NoSuchFileException(java.nio.file.NoSuchFileException) SerializationException(org.apache.kafka.common.errors.SerializationException) IncompatibleKsqlCommandVersionException(io.confluent.ksql.rest.server.resources.IncompatibleKsqlCommandVersionException) OutOfOrderSequenceException(org.apache.kafka.common.errors.OutOfOrderSequenceException) ProducerFencedException(org.apache.kafka.common.errors.ProducerFencedException) KsqlException(io.confluent.ksql.util.KsqlException) TimeoutException(org.apache.kafka.common.errors.TimeoutException) AuthorizationException(org.apache.kafka.common.errors.AuthorizationException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) Command(io.confluent.ksql.rest.server.computation.Command) IncompatibleKsqlCommandVersionException(io.confluent.ksql.rest.server.resources.IncompatibleKsqlCommandVersionException) CommandId(io.confluent.ksql.rest.entity.CommandId) Pair(io.confluent.ksql.util.Pair)

Aggregations

IncompatibleKsqlCommandVersionException (io.confluent.ksql.rest.server.resources.IncompatibleKsqlCommandVersionException)4 Test (org.junit.Test)3 InOrder (org.mockito.InOrder)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ValueInstantiationException (com.fasterxml.jackson.databind.exc.ValueInstantiationException)1 CommandId (io.confluent.ksql.rest.entity.CommandId)1 Command (io.confluent.ksql.rest.server.computation.Command)1 KsqlException (io.confluent.ksql.util.KsqlException)1 Pair (io.confluent.ksql.util.Pair)1 IOException (java.io.IOException)1 NoSuchFileException (java.nio.file.NoSuchFileException)1 ArrayList (java.util.ArrayList)1 ExecutionException (java.util.concurrent.ExecutionException)1 AuthorizationException (org.apache.kafka.common.errors.AuthorizationException)1 OutOfOrderSequenceException (org.apache.kafka.common.errors.OutOfOrderSequenceException)1 ProducerFencedException (org.apache.kafka.common.errors.ProducerFencedException)1 SerializationException (org.apache.kafka.common.errors.SerializationException)1 TimeoutException (org.apache.kafka.common.errors.TimeoutException)1