Search in sources :

Example 6 with KafkaException

use of org.apache.kafka.common.KafkaException in project kafka by apache.

the class StreamTask method punctuate.

/**
     * @throws IllegalStateException if the current node is not null
     */
@Override
public void punctuate(ProcessorNode node, long timestamp) {
    if (processorContext.currentNode() != null)
        throw new IllegalStateException(String.format("%s Current node is not null", logPrefix));
    final StampedRecord stampedRecord = new StampedRecord(DUMMY_RECORD, timestamp);
    updateProcessorContext(createRecordContext(stampedRecord), node);
    log.trace("{} Punctuating processor {} with timestamp {}", logPrefix, node.name(), timestamp);
    try {
        node.punctuate(timestamp);
    } catch (KafkaException ke) {
        throw new StreamsException(String.format("Exception caught in punctuate. taskId=%s processor=%s", id, node.name()), ke);
    } finally {
        processorContext.setCurrentNode(null);
    }
}
Also used : StreamsException(org.apache.kafka.streams.errors.StreamsException) KafkaException(org.apache.kafka.common.KafkaException)

Example 7 with KafkaException

use of org.apache.kafka.common.KafkaException in project kafka by apache.

the class AbstractTaskTest method shouldThrowProcessorStateExceptionOnInitializeOffsetsWhenKafkaException.

@Test(expected = ProcessorStateException.class)
public void shouldThrowProcessorStateExceptionOnInitializeOffsetsWhenKafkaException() throws Exception {
    final Consumer consumer = mockConsumer(new KafkaException("blah"));
    final AbstractTask task = createTask(consumer);
    task.initializeOffsetLimits();
}
Also used : Consumer(org.apache.kafka.clients.consumer.Consumer) MockConsumer(org.apache.kafka.clients.consumer.MockConsumer) KafkaException(org.apache.kafka.common.KafkaException) Test(org.junit.Test)

Example 8 with KafkaException

use of org.apache.kafka.common.KafkaException in project kafka by apache.

the class StreamTaskTest method shouldWrapKafkaExceptionsWithStreamsExceptionAndAddContext.

@SuppressWarnings("unchecked")
@Test
public void shouldWrapKafkaExceptionsWithStreamsExceptionAndAddContext() throws Exception {
    final MockSourceNode processorNode = new MockSourceNode(topic1, intDeserializer, intDeserializer) {

        @Override
        public void process(final Object key, final Object value) {
            throw new KafkaException("KABOOM!");
        }
    };
    final List<ProcessorNode> processorNodes = Collections.<ProcessorNode>singletonList(processorNode);
    final Map<String, SourceNode> sourceNodes = Collections.<String, SourceNode>singletonMap(topic1[0], processorNode);
    final ProcessorTopology topology = new ProcessorTopology(processorNodes, sourceNodes, Collections.<String, SinkNode>emptyMap(), Collections.<StateStore>emptyList(), Collections.<String, String>emptyMap(), Collections.<StateStore>emptyList());
    task.close();
    task = new StreamTask(taskId00, applicationId, partitions, topology, consumer, changelogReader, config, streamsMetrics, stateDirectory, testCache, time, recordCollector);
    final int offset = 20;
    task.addRecords(partition1, Collections.singletonList(new ConsumerRecord<>(partition1.topic(), partition1.partition(), offset, 0L, TimestampType.CREATE_TIME, 0L, 0, 0, recordKey, recordValue)));
    try {
        task.process();
        fail("Should've thrown StreamsException");
    } catch (StreamsException e) {
        final String message = e.getMessage();
        assertTrue("message=" + message + " should contain topic", message.contains("topic=" + topic1[0]));
        assertTrue("message=" + message + " should contain partition", message.contains("partition=" + partition1.partition()));
        assertTrue("message=" + message + " should contain offset", message.contains("offset=" + offset));
        assertTrue("message=" + message + " should contain processor", message.contains("processor=" + processorNode.name()));
    }
}
Also used : StreamsException(org.apache.kafka.streams.errors.StreamsException) OffsetCheckpoint(org.apache.kafka.streams.state.internals.OffsetCheckpoint) ConsumerRecord(org.apache.kafka.clients.consumer.ConsumerRecord) MockSourceNode(org.apache.kafka.test.MockSourceNode) MockProcessorNode(org.apache.kafka.test.MockProcessorNode) MockSourceNode(org.apache.kafka.test.MockSourceNode) KafkaException(org.apache.kafka.common.KafkaException) Test(org.junit.Test)

Example 9 with KafkaException

use of org.apache.kafka.common.KafkaException in project kafka by apache.

the class SaslClientAuthenticator method configure.

public void configure(TransportLayer transportLayer, PrincipalBuilder principalBuilder, Map<String, ?> configs) throws KafkaException {
    try {
        this.transportLayer = transportLayer;
        this.configs = configs;
        setSaslState(handshakeRequestEnable ? SaslState.SEND_HANDSHAKE_REQUEST : SaslState.INITIAL);
        // determine client principal from subject.
        if (!subject.getPrincipals().isEmpty()) {
            Principal clientPrincipal = subject.getPrincipals().iterator().next();
            this.clientPrincipalName = clientPrincipal.getName();
        } else {
            clientPrincipalName = null;
        }
        callbackHandler = new SaslClientCallbackHandler();
        callbackHandler.configure(configs, Mode.CLIENT, subject, mechanism);
        saslClient = createSaslClient();
    } catch (Exception e) {
        throw new KafkaException("Failed to configure SaslClientAuthenticator", e);
    }
}
Also used : KafkaException(org.apache.kafka.common.KafkaException) Principal(java.security.Principal) KafkaPrincipal(org.apache.kafka.common.security.auth.KafkaPrincipal) KafkaException(org.apache.kafka.common.KafkaException) SaslException(javax.security.sasl.SaslException) SchemaException(org.apache.kafka.common.protocol.types.SchemaException) IllegalSaslStateException(org.apache.kafka.common.errors.IllegalSaslStateException) PrivilegedActionException(java.security.PrivilegedActionException) IOException(java.io.IOException) UnsupportedSaslMechanismException(org.apache.kafka.common.errors.UnsupportedSaslMechanismException) AuthenticationException(org.apache.kafka.common.errors.AuthenticationException)

Example 10 with KafkaException

use of org.apache.kafka.common.KafkaException in project kafka by apache.

the class SslChannelBuilder method buildChannel.

public KafkaChannel buildChannel(String id, SelectionKey key, int maxReceiveSize) throws KafkaException {
    try {
        SslTransportLayer transportLayer = buildTransportLayer(sslFactory, id, key);
        Authenticator authenticator = new DefaultAuthenticator();
        authenticator.configure(transportLayer, this.principalBuilder, this.configs);
        return new KafkaChannel(id, transportLayer, authenticator, maxReceiveSize);
    } catch (Exception e) {
        log.info("Failed to create channel due to ", e);
        throw new KafkaException(e);
    }
}
Also used : KafkaException(org.apache.kafka.common.KafkaException) KafkaException(org.apache.kafka.common.KafkaException) IOException(java.io.IOException)

Aggregations

KafkaException (org.apache.kafka.common.KafkaException)262 Test (org.junit.Test)69 TopicPartition (org.apache.kafka.common.TopicPartition)56 Test (org.junit.jupiter.api.Test)47 HashMap (java.util.HashMap)40 IOException (java.io.IOException)39 StreamsException (org.apache.kafka.streams.errors.StreamsException)34 Map (java.util.Map)32 TimeoutException (org.apache.kafka.common.errors.TimeoutException)28 ArrayList (java.util.ArrayList)27 List (java.util.List)21 ByteBuffer (java.nio.ByteBuffer)19 ExecutionException (java.util.concurrent.ExecutionException)19 ConfigException (org.apache.kafka.common.config.ConfigException)16 TopicAuthorizationException (org.apache.kafka.common.errors.TopicAuthorizationException)14 HashSet (java.util.HashSet)13 Properties (java.util.Properties)13 Set (java.util.Set)11 Collectors (java.util.stream.Collectors)11 RecordMetadata (org.apache.kafka.clients.producer.RecordMetadata)11