Search in sources :

Example 26 with KafkaException

use of org.apache.kafka.common.KafkaException in project apache-kafka-on-k8s by banzaicloud.

the class SslFactory method reconfigure.

@Override
public void reconfigure(Map<String, ?> configs) throws KafkaException {
    SecurityStore newKeystore = maybeCreateNewKeystore(configs);
    if (newKeystore != null) {
        try {
            this.sslContext = createSSLContext(newKeystore);
            this.keystore = newKeystore;
        } catch (Exception e) {
            throw new ConfigException("Reconfiguration of SSL keystore failed", e);
        }
    }
}
Also used : ConfigException(org.apache.kafka.common.config.ConfigException) KafkaException(org.apache.kafka.common.KafkaException) GeneralSecurityException(java.security.GeneralSecurityException) IOException(java.io.IOException) ConfigException(org.apache.kafka.common.config.ConfigException) SSLException(javax.net.ssl.SSLException)

Example 27 with KafkaException

use of org.apache.kafka.common.KafkaException in project apache-kafka-on-k8s by banzaicloud.

the class SslFactory method configure.

@Override
public void configure(Map<String, ?> configs) throws KafkaException {
    this.protocol = (String) configs.get(SslConfigs.SSL_PROTOCOL_CONFIG);
    this.provider = (String) configs.get(SslConfigs.SSL_PROVIDER_CONFIG);
    @SuppressWarnings("unchecked") List<String> cipherSuitesList = (List<String>) configs.get(SslConfigs.SSL_CIPHER_SUITES_CONFIG);
    if (cipherSuitesList != null && !cipherSuitesList.isEmpty())
        this.cipherSuites = cipherSuitesList.toArray(new String[cipherSuitesList.size()]);
    @SuppressWarnings("unchecked") List<String> enabledProtocolsList = (List<String>) configs.get(SslConfigs.SSL_ENABLED_PROTOCOLS_CONFIG);
    if (enabledProtocolsList != null && !enabledProtocolsList.isEmpty())
        this.enabledProtocols = enabledProtocolsList.toArray(new String[enabledProtocolsList.size()]);
    String endpointIdentification = (String) configs.get(SslConfigs.SSL_ENDPOINT_IDENTIFICATION_ALGORITHM_CONFIG);
    if (endpointIdentification != null)
        this.endpointIdentification = endpointIdentification;
    String secureRandomImplementation = (String) configs.get(SslConfigs.SSL_SECURE_RANDOM_IMPLEMENTATION_CONFIG);
    if (secureRandomImplementation != null) {
        try {
            this.secureRandomImplementation = SecureRandom.getInstance(secureRandomImplementation);
        } catch (GeneralSecurityException e) {
            throw new KafkaException(e);
        }
    }
    String clientAuthConfig = clientAuthConfigOverride;
    if (clientAuthConfig == null)
        clientAuthConfig = (String) configs.get(BrokerSecurityConfigs.SSL_CLIENT_AUTH_CONFIG);
    if (clientAuthConfig != null) {
        if (clientAuthConfig.equals("required"))
            this.needClientAuth = true;
        else if (clientAuthConfig.equals("requested"))
            this.wantClientAuth = true;
    }
    this.kmfAlgorithm = (String) configs.get(SslConfigs.SSL_KEYMANAGER_ALGORITHM_CONFIG);
    this.tmfAlgorithm = (String) configs.get(SslConfigs.SSL_TRUSTMANAGER_ALGORITHM_CONFIG);
    this.keystore = createKeystore((String) configs.get(SslConfigs.SSL_KEYSTORE_TYPE_CONFIG), (String) configs.get(SslConfigs.SSL_KEYSTORE_LOCATION_CONFIG), (Password) configs.get(SslConfigs.SSL_KEYSTORE_PASSWORD_CONFIG), (Password) configs.get(SslConfigs.SSL_KEY_PASSWORD_CONFIG));
    this.truststore = createTruststore((String) configs.get(SslConfigs.SSL_TRUSTSTORE_TYPE_CONFIG), (String) configs.get(SslConfigs.SSL_TRUSTSTORE_LOCATION_CONFIG), (Password) configs.get(SslConfigs.SSL_TRUSTSTORE_PASSWORD_CONFIG));
    try {
        this.sslContext = createSSLContext(keystore);
    } catch (Exception e) {
        throw new KafkaException(e);
    }
}
Also used : GeneralSecurityException(java.security.GeneralSecurityException) ArrayList(java.util.ArrayList) List(java.util.List) KafkaException(org.apache.kafka.common.KafkaException) KafkaException(org.apache.kafka.common.KafkaException) GeneralSecurityException(java.security.GeneralSecurityException) IOException(java.io.IOException) ConfigException(org.apache.kafka.common.config.ConfigException) SSLException(javax.net.ssl.SSLException) Password(org.apache.kafka.common.config.types.Password)

Example 28 with KafkaException

use of org.apache.kafka.common.KafkaException in project apache-kafka-on-k8s by banzaicloud.

the class Sanitizer method sanitize.

/**
 * Sanitize `name` for safe use as JMX metric name as well as ZooKeeper node name
 * using URL-encoding.
 */
public static String sanitize(String name) {
    String encoded = "";
    try {
        encoded = URLEncoder.encode(name, StandardCharsets.UTF_8.name());
        StringBuilder builder = new StringBuilder();
        for (int i = 0; i < encoded.length(); i++) {
            char c = encoded.charAt(i);
            if (c == '*') {
                // Metric ObjectName treats * as pattern
                builder.append("%2A");
            } else if (c == '+') {
                // Space URL-encoded as +, replace with percent encoding
                builder.append("%20");
            } else {
                builder.append(c);
            }
        }
        return builder.toString();
    } catch (UnsupportedEncodingException e) {
        throw new KafkaException(e);
    }
}
Also used : UnsupportedEncodingException(java.io.UnsupportedEncodingException) KafkaException(org.apache.kafka.common.KafkaException)

Example 29 with KafkaException

use of org.apache.kafka.common.KafkaException in project apache-kafka-on-k8s by banzaicloud.

the class StreamTaskTest method shouldWrapKafkaExceptionsWithStreamsExceptionAndAddContextWhenPunctuatingStreamTime.

@Test
public void shouldWrapKafkaExceptionsWithStreamsExceptionAndAddContextWhenPunctuatingStreamTime() {
    task = createStatelessTask(false);
    task.initializeStateStores();
    task.initializeTopology();
    try {
        task.punctuate(processorStreamTime, 1, PunctuationType.STREAM_TIME, new Punctuator() {

            @Override
            public void punctuate(long timestamp) {
                throw new KafkaException("KABOOM!");
            }
        });
        fail("Should've thrown StreamsException");
    } catch (final StreamsException e) {
        final String message = e.getMessage();
        assertTrue("message=" + message + " should contain processor", message.contains("processor '" + processorStreamTime.name() + "'"));
        assertThat(task.processorContext.currentNode(), nullValue());
    }
}
Also used : Punctuator(org.apache.kafka.streams.processor.Punctuator) StreamsException(org.apache.kafka.streams.errors.StreamsException) KafkaException(org.apache.kafka.common.KafkaException) Test(org.junit.Test)

Example 30 with KafkaException

use of org.apache.kafka.common.KafkaException in project apache-kafka-on-k8s by banzaicloud.

the class RecordCollectorTest method shouldThrowStreamsExceptionOnAnyExceptionButProducerFencedException.

@SuppressWarnings("unchecked")
@Test(expected = StreamsException.class)
public void shouldThrowStreamsExceptionOnAnyExceptionButProducerFencedException() {
    final RecordCollector collector = new RecordCollectorImpl(new MockProducer(cluster, true, new DefaultPartitioner(), byteArraySerializer, byteArraySerializer) {

        @Override
        public synchronized Future<RecordMetadata> send(final ProducerRecord record, final Callback callback) {
            throw new KafkaException();
        }
    }, "test", logContext, new DefaultProductionExceptionHandler());
    collector.send("topic1", "3", "0", null, stringSerializer, stringSerializer, streamPartitioner);
}
Also used : MockProducer(org.apache.kafka.clients.producer.MockProducer) Callback(org.apache.kafka.clients.producer.Callback) DefaultPartitioner(org.apache.kafka.clients.producer.internals.DefaultPartitioner) DefaultProductionExceptionHandler(org.apache.kafka.streams.errors.DefaultProductionExceptionHandler) ProducerRecord(org.apache.kafka.clients.producer.ProducerRecord) Future(java.util.concurrent.Future) KafkaException(org.apache.kafka.common.KafkaException) Test(org.junit.Test)

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