Search in sources :

Example 36 with ConfigException

use of org.apache.kafka.common.config.ConfigException in project kafka by apache.

the class SslFactoryTest method verifyKeystoreVerifiableUsingTruststore.

private void verifyKeystoreVerifiableUsingTruststore(boolean usePem, String tlsProtocol) throws Exception {
    File trustStoreFile1 = usePem ? null : File.createTempFile("truststore1", ".jks");
    Map<String, Object> sslConfig1 = sslConfigsBuilder(Mode.SERVER).createNewTrustStore(trustStoreFile1).usePem(usePem).build();
    SslFactory sslFactory = new SslFactory(Mode.SERVER, null, true);
    sslFactory.configure(sslConfig1);
    File trustStoreFile2 = usePem ? null : File.createTempFile("truststore2", ".jks");
    Map<String, Object> sslConfig2 = sslConfigsBuilder(Mode.SERVER).createNewTrustStore(trustStoreFile2).usePem(usePem).build();
    // listener to stores that may not work with other brokers where the update hasn't yet been performed.
    try {
        sslFactory.validateReconfiguration(sslConfig2);
        fail("ValidateReconfiguration did not fail as expected");
    } catch (ConfigException e) {
    // Expected exception
    }
}
Also used : ConfigException(org.apache.kafka.common.config.ConfigException) File(java.io.File)

Example 37 with ConfigException

use of org.apache.kafka.common.config.ConfigException in project kafka by apache.

the class KafkaAdminClientTest method testDefaultApiTimeoutAndRequestTimeoutConflicts.

@Test
public void testDefaultApiTimeoutAndRequestTimeoutConflicts() {
    final AdminClientConfig config = newConfMap(AdminClientConfig.DEFAULT_API_TIMEOUT_MS_CONFIG, "500");
    KafkaException exception = assertThrows(KafkaException.class, () -> KafkaAdminClient.createInternal(config, null));
    assertTrue(exception.getCause() instanceof ConfigException);
}
Also used : KafkaException(org.apache.kafka.common.KafkaException) ConfigException(org.apache.kafka.common.config.ConfigException) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Test(org.junit.jupiter.api.Test)

Example 38 with ConfigException

use of org.apache.kafka.common.config.ConfigException in project kafka by apache.

the class WorkerConfig method validateHttpResponseHeaderConfig.

// Visible for testing
static void validateHttpResponseHeaderConfig(String config) {
    try {
        // validate format
        String[] configTokens = config.trim().split("\\s+", 2);
        if (configTokens.length != 2) {
            throw new ConfigException(String.format("Invalid format of header config '%s'. " + "Expected: '[ation] [header name]:[header value]'", config));
        }
        // validate action
        String method = configTokens[0].trim();
        validateHeaderConfigAction(method);
        // validate header name and header value pair
        String header = configTokens[1];
        String[] headerTokens = header.trim().split(":");
        if (headerTokens.length != 2) {
            throw new ConfigException(String.format("Invalid format of header name and header value pair '%s'. " + "Expected: '[header name]:[header value]'", header));
        }
        // validate header name
        String headerName = headerTokens[0].trim();
        if (headerName.isEmpty() || headerName.matches(".*\\s+.*")) {
            throw new ConfigException(String.format("Invalid header name '%s'. " + "The '[header name]' cannot contain whitespace", headerName));
        }
    } catch (ArrayIndexOutOfBoundsException e) {
        throw new ConfigException(String.format("Invalid header config '%s'.", config), e);
    }
}
Also used : ConfigException(org.apache.kafka.common.config.ConfigException)

Example 39 with ConfigException

use of org.apache.kafka.common.config.ConfigException in project kafka by apache.

the class SinkConnectorConfig method validate.

/**
 * Throw an exception if the passed-in properties do not constitute a valid sink.
 * @param props sink configuration properties
 */
public static void validate(Map<String, String> props) {
    final boolean hasTopicsConfig = hasTopicsConfig(props);
    final boolean hasTopicsRegexConfig = hasTopicsRegexConfig(props);
    final boolean hasDlqTopicConfig = hasDlqTopicConfig(props);
    if (hasTopicsConfig && hasTopicsRegexConfig) {
        throw new ConfigException(SinkTask.TOPICS_CONFIG + " and " + SinkTask.TOPICS_REGEX_CONFIG + " are mutually exclusive options, but both are set.");
    }
    if (!hasTopicsConfig && !hasTopicsRegexConfig) {
        throw new ConfigException("Must configure one of " + SinkTask.TOPICS_CONFIG + " or " + SinkTask.TOPICS_REGEX_CONFIG);
    }
    if (hasDlqTopicConfig) {
        String dlqTopic = props.get(DLQ_TOPIC_NAME_CONFIG).trim();
        if (hasTopicsConfig) {
            List<String> topics = parseTopicsList(props);
            if (topics.contains(dlqTopic)) {
                throw new ConfigException(String.format("The DLQ topic '%s' may not be included in the list of " + "topics ('%s=%s') consumed by the connector", dlqTopic, SinkTask.TOPICS_REGEX_CONFIG, topics));
            }
        }
        if (hasTopicsRegexConfig) {
            String topicsRegexStr = props.get(SinkTask.TOPICS_REGEX_CONFIG);
            Pattern pattern = Pattern.compile(topicsRegexStr);
            if (pattern.matcher(dlqTopic).matches()) {
                throw new ConfigException(String.format("The DLQ topic '%s' may not be included in the regex matching the " + "topics ('%s=%s') consumed by the connector", dlqTopic, SinkTask.TOPICS_REGEX_CONFIG, topicsRegexStr));
            }
        }
    }
}
Also used : Pattern(java.util.regex.Pattern) ConfigException(org.apache.kafka.common.config.ConfigException)

Example 40 with ConfigException

use of org.apache.kafka.common.config.ConfigException in project kafka by apache.

the class JmxReporter method compilePredicate.

public static Predicate<String> compilePredicate(Map<String, ?> originalConfig) {
    Map<String, ?> configs = ConfigUtils.translateDeprecatedConfigs(originalConfig, new String[][] { { INCLUDE_CONFIG, INCLUDE_CONFIG_ALIAS }, { EXCLUDE_CONFIG, EXCLUDE_CONFIG_ALIAS } });
    String include = (String) configs.get(INCLUDE_CONFIG);
    String exclude = (String) configs.get(EXCLUDE_CONFIG);
    if (include == null) {
        include = DEFAULT_INCLUDE;
    }
    if (exclude == null) {
        exclude = DEFAULT_EXCLUDE;
    }
    try {
        Pattern includePattern = Pattern.compile(include);
        Pattern excludePattern = Pattern.compile(exclude);
        return s -> includePattern.matcher(s).matches() && !excludePattern.matcher(s).matches();
    } catch (PatternSyntaxException e) {
        throw new ConfigException("JMX filter for configuration" + METRICS_CONFIG_PREFIX + ".(include/exclude) is not a valid regular expression");
    }
}
Also used : AttributeNotFoundException(javax.management.AttributeNotFoundException) LoggerFactory(org.slf4j.LoggerFactory) KafkaException(org.apache.kafka.common.KafkaException) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) HashMap(java.util.HashMap) AttributeList(javax.management.AttributeList) Sanitizer(org.apache.kafka.common.utils.Sanitizer) Attribute(javax.management.Attribute) MBeanServer(javax.management.MBeanServer) Map(java.util.Map) MetricName(org.apache.kafka.common.MetricName) ManagementFactory(java.lang.management.ManagementFactory) ConfigUtils(org.apache.kafka.common.utils.ConfigUtils) Utils(org.apache.kafka.common.utils.Utils) Logger(org.slf4j.Logger) PatternSyntaxException(java.util.regex.PatternSyntaxException) Predicate(java.util.function.Predicate) Set(java.util.Set) ObjectName(javax.management.ObjectName) ConfigException(org.apache.kafka.common.config.ConfigException) MBeanInfo(javax.management.MBeanInfo) MalformedObjectNameException(javax.management.MalformedObjectNameException) Objects(java.util.Objects) List(java.util.List) JMException(javax.management.JMException) Pattern(java.util.regex.Pattern) DynamicMBean(javax.management.DynamicMBean) Pattern(java.util.regex.Pattern) ConfigException(org.apache.kafka.common.config.ConfigException) PatternSyntaxException(java.util.regex.PatternSyntaxException)

Aggregations

ConfigException (org.apache.kafka.common.config.ConfigException)136 HashMap (java.util.HashMap)29 Test (org.junit.jupiter.api.Test)28 Test (org.junit.Test)20 Properties (java.util.Properties)10 KafkaException (org.apache.kafka.common.KafkaException)10 ArrayList (java.util.ArrayList)9 List (java.util.List)9 Pattern (java.util.regex.Pattern)9 Serde (org.apache.kafka.common.serialization.Serde)8 SimpleConfig (org.apache.kafka.connect.transforms.util.SimpleConfig)8 File (java.io.File)7 SSLContext (javax.net.ssl.SSLContext)7 Map (java.util.Map)6 ByteArraySerializer (org.apache.kafka.common.serialization.ByteArraySerializer)6 KeyStore (java.security.KeyStore)5 KeyManagerFactory (javax.net.ssl.KeyManagerFactory)5 TrustManagerFactory (javax.net.ssl.TrustManagerFactory)5 ConfigDef (org.apache.kafka.common.config.ConfigDef)5 IOException (java.io.IOException)4