Search in sources :

Example 71 with ConfigException

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

the class ClientUtils method parseAndValidateAddresses.

public static List<InetSocketAddress> parseAndValidateAddresses(List<String> urls) {
    List<InetSocketAddress> addresses = new ArrayList<>();
    for (String url : urls) {
        if (url != null && !url.isEmpty()) {
            try {
                String host = getHost(url);
                Integer port = getPort(url);
                if (host == null || port == null)
                    throw new ConfigException("Invalid url in " + CommonClientConfigs.BOOTSTRAP_SERVERS_CONFIG + ": " + url);
                InetSocketAddress address = new InetSocketAddress(host, port);
                if (address.isUnresolved()) {
                    log.warn("Removing server {} from {} as DNS resolution failed for {}", url, CommonClientConfigs.BOOTSTRAP_SERVERS_CONFIG, host);
                } else {
                    addresses.add(address);
                }
            } catch (IllegalArgumentException e) {
                throw new ConfigException("Invalid port in " + CommonClientConfigs.BOOTSTRAP_SERVERS_CONFIG + ": " + url);
            }
        }
    }
    if (addresses.isEmpty())
        throw new ConfigException("No resolvable bootstrap urls given in " + CommonClientConfigs.BOOTSTRAP_SERVERS_CONFIG);
    return addresses;
}
Also used : InetSocketAddress(java.net.InetSocketAddress) ArrayList(java.util.ArrayList) ConfigException(org.apache.kafka.common.config.ConfigException)

Example 72 with ConfigException

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

the class WindowedSerializer method configure.

@Override
public void configure(Map<String, ?> configs, boolean isKey) {
    if (inner == null) {
        String propertyName = isKey ? "key.serializer.inner.class" : "value.serializer.inner.class";
        Object innerSerializerClass = configs.get(propertyName);
        propertyName = (innerSerializerClass == null) ? "serializer.inner.class" : propertyName;
        String value = null;
        try {
            value = (String) configs.get(propertyName);
            inner = Serializer.class.cast(Utils.newInstance(value, Serializer.class));
            inner.configure(configs, isKey);
        } catch (ClassNotFoundException e) {
            throw new ConfigException(propertyName, value, "Class " + value + " could not be found.");
        }
    }
}
Also used : ConfigException(org.apache.kafka.common.config.ConfigException) Serializer(org.apache.kafka.common.serialization.Serializer)

Example 73 with ConfigException

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

the class StreamPartitionAssignorTest method shouldThrowExceptionIfApplicationServerConfigIsNotHostPortPair.

@Test
public void shouldThrowExceptionIfApplicationServerConfigIsNotHostPortPair() throws Exception {
    final Properties properties = configProps();
    final String myEndPoint = "localhost";
    properties.put(StreamsConfig.APPLICATION_SERVER_CONFIG, myEndPoint);
    final StreamsConfig config = new StreamsConfig(properties);
    final UUID uuid1 = UUID.randomUUID();
    final String client1 = "client1";
    final String applicationId = "application-id";
    builder.setApplicationId(applicationId);
    final StreamThread streamThread = new StreamThread(builder, config, mockClientSupplier, applicationId, client1, uuid1, new Metrics(), Time.SYSTEM, new StreamsMetadataState(builder, StreamsMetadataState.UNKNOWN_HOST), 0);
    partitionAssignor.setInternalTopicManager(new MockInternalTopicManager(streamThread.config, mockClientSupplier.restoreConsumer));
    try {
        partitionAssignor.configure(config.getConsumerConfigs(streamThread, applicationId, client1));
        Assert.fail("expected to an exception due to invalid config");
    } catch (ConfigException e) {
    // pass
    }
}
Also used : Metrics(org.apache.kafka.common.metrics.Metrics) MockInternalTopicManager(org.apache.kafka.test.MockInternalTopicManager) ConfigException(org.apache.kafka.common.config.ConfigException) Properties(java.util.Properties) UUID(java.util.UUID) StreamsConfig(org.apache.kafka.streams.StreamsConfig) Test(org.junit.Test)

Example 74 with ConfigException

use of org.apache.kafka.common.config.ConfigException in project cruise-control by linkedin.

the class CruiseControlMetricsReporterSampler method configure.

@Override
public void configure(Map<String, ?> configs) {
    String numSamplersString = (String) configs.get(KafkaCruiseControlConfig.NUM_METRIC_FETCHERS_CONFIG);
    if (numSamplersString != null && Integer.parseInt(numSamplersString) != 1) {
        throw new ConfigException("CruiseControlMetricsReporterSampler is not thread safe. Please change " + KafkaCruiseControlConfig.NUM_METRIC_FETCHERS_CONFIG + " to 1");
    }
    String bootstrapServers = (String) configs.get(METRIC_REPORTER_SAMPLER_BOOTSTRAP_SERVERS);
    if (bootstrapServers == null) {
        bootstrapServers = (String) configs.get(KafkaCruiseControlConfig.BOOTSTRAP_SERVERS_CONFIG);
    }
    String metricReporterTopic = (String) configs.get(METRIC_REPORTER_TOPIC_PATTERN);
    if (metricReporterTopic == null) {
        metricReporterTopic = CruiseControlMetricsReporterConfig.DEFAULT_CRUISE_CONTROL_METRICS_TOPIC;
    }
    String groupId = (String) configs.get(METRIC_REPORTER_SAMPLER_GROUP_ID);
    if (groupId == null) {
        groupId = DEFAULT_METRIC_REPORTER_SAMPLER_GROUP_ID + "-" + RANDOM.nextLong();
    }
    Properties consumerProps = new Properties();
    consumerProps.putAll(configs);
    Random random = new Random();
    consumerProps.setProperty(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapServers);
    consumerProps.setProperty(ConsumerConfig.GROUP_ID_CONFIG, groupId);
    consumerProps.setProperty(ConsumerConfig.CLIENT_ID_CONFIG, DEFAULT_METRIC_REPORTER_SAMPLER_GROUP_ID + "Consumer-" + random.nextInt());
    consumerProps.setProperty(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "latest");
    consumerProps.setProperty(ConsumerConfig.ENABLE_AUTO_COMMIT_CONFIG, "false");
    consumerProps.setProperty(ConsumerConfig.MAX_POLL_RECORDS_CONFIG, Integer.toString(Integer.MAX_VALUE));
    consumerProps.setProperty(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class.getName());
    consumerProps.setProperty(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, MetricSerde.class.getName());
    consumerProps.setProperty(ConsumerConfig.MAX_POLL_INTERVAL_MS_CONFIG, Integer.toString(Integer.MAX_VALUE));
    _metricConsumer = new KafkaConsumer<>(consumerProps);
    _metricConsumer.subscribe(Pattern.compile(metricReporterTopic), new ConsumerRebalanceListener() {

        @Override
        public void onPartitionsRevoked(Collection<TopicPartition> collection) {
            _metricConsumer.commitSync();
        }

        @Override
        public void onPartitionsAssigned(Collection<TopicPartition> collection) {
        // Do nothing
        }
    });
    Pattern topicPattern = Pattern.compile(metricReporterTopic);
    for (String topic : _metricConsumer.listTopics().keySet()) {
        if (topicPattern.matcher(topic).matches()) {
            return;
        }
    }
    throw new IllegalStateException("Cruise Control cannot find sampling topic matches " + metricReporterTopic + " in the target cluster.");
}
Also used : Pattern(java.util.regex.Pattern) StringDeserializer(org.apache.kafka.common.serialization.StringDeserializer) ConfigException(org.apache.kafka.common.config.ConfigException) Properties(java.util.Properties) ConsumerRebalanceListener(org.apache.kafka.clients.consumer.ConsumerRebalanceListener) Random(java.util.Random) TopicPartition(org.apache.kafka.common.TopicPartition) MetricSerde(com.linkedin.kafka.cruisecontrol.metricsreporter.metric.MetricSerde)

Example 75 with ConfigException

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

the class ConfigUtils method getAbsoluteFile.

/**
 * Method is used to return a File checking to ensure that it is an absolute path.
 *
 * @param config config to read the value from
 * @param key    key for the value
 * @return File for the config value.
 */
public static File getAbsoluteFile(AbstractConfig config, String key) {
    Preconditions.checkNotNull(config, "config cannot be null");
    String path = config.getString(key);
    File file = new File(path);
    if (!file.isAbsolute()) {
        throw new ConfigException(key, path, "Must be an absolute path.");
    }
    return new File(path);
}
Also used : ConfigException(org.apache.kafka.common.config.ConfigException) File(java.io.File)

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