Search in sources :

Example 61 with ConfigException

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

the class HasHeaderKeyTest method testNameRequiredInConfig.

@Test
public void testNameRequiredInConfig() {
    Map<String, String> props = new HashMap<>();
    ConfigException e = assertThrows(ConfigException.class, () -> config(props));
    assertTrue(e.getMessage().contains("Missing required configuration \"name\""));
}
Also used : HashMap(java.util.HashMap) ConfigException(org.apache.kafka.common.config.ConfigException) Test(org.junit.jupiter.api.Test)

Example 62 with ConfigException

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

the class RaftConfig method parseVoterConnections.

public static Map<Integer, AddressSpec> parseVoterConnections(List<String> voterEntries) {
    Map<Integer, AddressSpec> voterMap = new HashMap<>();
    for (String voterMapEntry : voterEntries) {
        String[] idAndAddress = voterMapEntry.split("@");
        if (idAndAddress.length != 2) {
            throw new ConfigException("Invalid configuration value for " + QUORUM_VOTERS_CONFIG + ". Each entry should be in the form `{id}@{host}:{port}`.");
        }
        Integer voterId = parseVoterId(idAndAddress[0]);
        String host = Utils.getHost(idAndAddress[1]);
        if (host == null) {
            throw new ConfigException("Failed to parse host name from entry " + voterMapEntry + " for the configuration " + QUORUM_VOTERS_CONFIG + ". Each entry should be in the form `{id}@{host}:{port}`.");
        }
        Integer port = Utils.getPort(idAndAddress[1]);
        if (port == null) {
            throw new ConfigException("Failed to parse host port from entry " + voterMapEntry + " for the configuration " + QUORUM_VOTERS_CONFIG + ". Each entry should be in the form `{id}@{host}:{port}`.");
        }
        InetSocketAddress address = new InetSocketAddress(host, port);
        if (address.equals(NON_ROUTABLE_ADDRESS)) {
            voterMap.put(voterId, UNKNOWN_ADDRESS_SPEC_INSTANCE);
        } else {
            voterMap.put(voterId, new InetAddressSpec(address));
        }
    }
    return voterMap;
}
Also used : HashMap(java.util.HashMap) InetSocketAddress(java.net.InetSocketAddress) ConfigException(org.apache.kafka.common.config.ConfigException)

Example 63 with ConfigException

use of org.apache.kafka.common.config.ConfigException in project connect-utils by jcustenborder.

the class ValidHostAndPort method ensureValid.

@Override
public void ensureValid(final String setting, final Object value) {
    if (value instanceof String) {
        final String input = (String) value;
        validate(setting, input);
    } else if (value instanceof List) {
        final List<String> inputs = (List<String>) value;
        for (String input : inputs) {
            validate(setting, input);
        }
    } else {
        throw new ConfigException(String.format("'%s' must be a String or List", setting));
    }
}
Also used : List(java.util.List) ConfigException(org.apache.kafka.common.config.ConfigException)

Example 64 with ConfigException

use of org.apache.kafka.common.config.ConfigException in project connect-utils by jcustenborder.

the class ValidHostnameAndPort method ensureValid.

@Override
public void ensureValid(String key, Object value) {
    log.trace("ensureValid('{}', '{}')", key, value);
    if (value instanceof String) {
        try {
            Matcher matcher = HOSTNAME_PATTERN.matcher((CharSequence) value);
            Preconditions.checkState(matcher.matches(), "'%s' does not match pattern '%s'.", key, HOSTNAME_PATTERN.pattern());
            final int port = Integer.parseInt(matcher.group(2));
            Preconditions.checkState(port >= 1 && port <= 65535, "'%s' port value %s is out of range. Port must be between 1 and 65535.", key, port);
        } catch (Exception ex) {
            throw new ConfigException(String.format("'%s' is not a valid hostname and port.", key), ex);
        }
    } else if (value instanceof List) {
        List<String> list = (List<String>) value;
        for (String s : list) {
            ensureValid(key, s);
        }
    } else {
        throw new ConfigException(String.format("'%s' must be a string or a list.", key));
    }
}
Also used : Matcher(java.util.regex.Matcher) ConfigException(org.apache.kafka.common.config.ConfigException) List(java.util.List) ConfigException(org.apache.kafka.common.config.ConfigException)

Example 65 with ConfigException

use of org.apache.kafka.common.config.ConfigException in project connect-utils by jcustenborder.

the class ValidCharsetTest method invalid.

@Test
public void invalid() {
    ConfigException configException = assertThrows(ConfigException.class, () -> {
        ConfigDef.Validator validator = new ValidCharset();
        validator.ensureValid("testing", 1234);
    });
}
Also used : ConfigException(org.apache.kafka.common.config.ConfigException) ConfigDef(org.apache.kafka.common.config.ConfigDef) Test(org.junit.jupiter.api.Test)

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