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;
}
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.");
}
}
}
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
}
}
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.");
}
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);
}
Aggregations