Search in sources :

Example 56 with ConfigException

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

the class TimeWindowedDeserializer method configure.

@SuppressWarnings("unchecked")
@Override
public void configure(final Map<String, ?> configs, final boolean isKey) {
    // check to see if the window size config is set and the window size is already set from the constructor
    final Long configWindowSize;
    if (configs.get(StreamsConfig.WINDOW_SIZE_MS_CONFIG) instanceof String) {
        configWindowSize = Long.parseLong((String) configs.get(StreamsConfig.WINDOW_SIZE_MS_CONFIG));
    } else {
        configWindowSize = (Long) configs.get(StreamsConfig.WINDOW_SIZE_MS_CONFIG);
    }
    if (windowSize != null && configWindowSize != null) {
        throw new IllegalArgumentException("Window size should not be set in both the time windowed deserializer constructor and the window.size.ms config");
    } else if (windowSize == null && configWindowSize == null) {
        throw new IllegalArgumentException("Window size needs to be set either through the time windowed deserializer " + "constructor or the window.size.ms config but not both");
    } else {
        windowSize = windowSize == null ? configWindowSize : windowSize;
    }
    final String windowedInnerClassSerdeConfig = (String) configs.get(StreamsConfig.WINDOWED_INNER_CLASS_SERDE);
    Serde<T> windowInnerClassSerde = null;
    if (windowedInnerClassSerdeConfig != null) {
        try {
            windowInnerClassSerde = Utils.newInstance(windowedInnerClassSerdeConfig, Serde.class);
        } catch (final ClassNotFoundException e) {
            throw new ConfigException(StreamsConfig.WINDOWED_INNER_CLASS_SERDE, windowedInnerClassSerdeConfig, "Serde class " + windowedInnerClassSerdeConfig + " could not be found.");
        }
    }
    if (inner != null && windowedInnerClassSerdeConfig != null) {
        if (!inner.getClass().getName().equals(windowInnerClassSerde.deserializer().getClass().getName())) {
            throw new IllegalArgumentException("Inner class deserializer set using constructor " + "(" + inner.getClass().getName() + ")" + " is different from the one set in windowed.inner.class.serde config " + "(" + windowInnerClassSerde.deserializer().getClass().getName() + ").");
        }
    } else if (inner == null && windowedInnerClassSerdeConfig == null) {
        throw new IllegalArgumentException("Inner class deserializer should be set either via  constructor " + "or via the windowed.inner.class.serde config");
    } else if (inner == null)
        inner = windowInnerClassSerde.deserializer();
}
Also used : Serde(org.apache.kafka.common.serialization.Serde) ConfigException(org.apache.kafka.common.config.ConfigException)

Example 57 with ConfigException

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

the class SessionWindowedDeserializer method configure.

@SuppressWarnings("unchecked")
@Override
public void configure(final Map<String, ?> configs, final boolean isKey) {
    final String windowedInnerClassSerdeConfig = (String) configs.get(StreamsConfig.WINDOWED_INNER_CLASS_SERDE);
    Serde<T> windowInnerClassSerde = null;
    if (windowedInnerClassSerdeConfig != null) {
        try {
            windowInnerClassSerde = Utils.newInstance(windowedInnerClassSerdeConfig, Serde.class);
        } catch (final ClassNotFoundException e) {
            throw new ConfigException(StreamsConfig.WINDOWED_INNER_CLASS_SERDE, windowedInnerClassSerdeConfig, "Serde class " + windowedInnerClassSerdeConfig + " could not be found.");
        }
    }
    if (inner != null && windowedInnerClassSerdeConfig != null) {
        if (!inner.getClass().getName().equals(windowInnerClassSerde.deserializer().getClass().getName())) {
            throw new IllegalArgumentException("Inner class deserializer set using constructor " + "(" + inner.getClass().getName() + ")" + " is different from the one set in windowed.inner.class.serde config " + "(" + windowInnerClassSerde.deserializer().getClass().getName() + ").");
        }
    } else if (inner == null && windowedInnerClassSerdeConfig == null) {
        throw new IllegalArgumentException("Inner class deserializer should be set either via constructor " + "or via the windowed.inner.class.serde config");
    } else if (inner == null)
        inner = windowInnerClassSerde.deserializer();
}
Also used : Serde(org.apache.kafka.common.serialization.Serde) ConfigException(org.apache.kafka.common.config.ConfigException)

Example 58 with ConfigException

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

the class WorkerConfigTest method testAdminListenersNotAllowingEmptyStrings.

@Test
public void testAdminListenersNotAllowingEmptyStrings() {
    Map<String, String> props = baseProps();
    props.put(WorkerConfig.ADMIN_LISTENERS_CONFIG, "http://a.b:9999,");
    ConfigException ce = assertThrows(ConfigException.class, () -> new WorkerConfig(WorkerConfig.baseConfigDef(), props));
    assertTrue(ce.getMessage().contains(" admin.listeners"));
}
Also used : ConfigException(org.apache.kafka.common.config.ConfigException) Test(org.junit.Test)

Example 59 with ConfigException

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

the class AssignorConfigurationTest method configsShouldRejectZeroWarmups.

@Test
public void configsShouldRejectZeroWarmups() {
    final ConfigException exception = assertThrows(ConfigException.class, () -> new AssignorConfiguration.AssignmentConfigs(1L, 0, 1, 1L));
    assertThat(exception.getMessage(), containsString("Invalid value 0 for configuration max.warmup.replicas"));
}
Also used : ConfigException(org.apache.kafka.common.config.ConfigException) Test(org.junit.Test)

Example 60 with ConfigException

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

the class AssignorConfiguration method userEndPoint.

public String userEndPoint() {
    final String configuredUserEndpoint = streamsConfig.getString(StreamsConfig.APPLICATION_SERVER_CONFIG);
    if (configuredUserEndpoint != null && !configuredUserEndpoint.isEmpty()) {
        try {
            final String host = getHost(configuredUserEndpoint);
            final Integer port = getPort(configuredUserEndpoint);
            if (host == null || port == null) {
                throw new ConfigException(String.format("%s Config %s isn't in the correct format. Expected a host:port pair but received %s", logPrefix, StreamsConfig.APPLICATION_SERVER_CONFIG, configuredUserEndpoint));
            }
        } catch (final NumberFormatException nfe) {
            throw new ConfigException(String.format("%s Invalid port supplied in %s for config %s: %s", logPrefix, configuredUserEndpoint, StreamsConfig.APPLICATION_SERVER_CONFIG, nfe));
        }
        return configuredUserEndpoint;
    } else {
        return null;
    }
}
Also used : ConfigException(org.apache.kafka.common.config.ConfigException)

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