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);
}
}
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();
}
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()));
}
}
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);
}
}
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);
}
}
Aggregations